#include<stdio.h>
#include<conio.h>

struct egde
{
       int nodeno;
       struct edge*next;
};

struct node
{
       int nodeno;
       struct node *next;
       struct edge *link;
};

struct node*graph=NULL;


typedef struct node node;
typedef struct egde edge;

node*find(int);
void insert_egde();
void insert_node();
void display();

int main()
{
    int ch,i,j;
    do{
               printf("\ninsert node");
               printf("\ninsert edge");
               printf("\ndisplay");
               printf("\nexit");
               printf("\nenter choice:");
               scanf("%d",&ch);
               switch(ch)
               {
                         case 1:
                              insert_node();
                              break;
                         case 2:
                              insert_egde();
                              break;
                         case 3:
                              display();
                              break;
                         case 4:
                              exit(0);
                              break;
                              
               }
        
       }while(ch!=5);    
}

void insert_node()
{
     int inf;
     node*new1;
     node*loc;
     printf("enter info:");
     scanf("%d",&inf);
     
     new1=(node*)malloc(sizeof(node));
     new1->nodeno=inf;
     new1->link=NULL;
     new1->next=NULL;
     if(graph==NULL)
     graph=new1;
     else
     {
         loc=find(inf);
         if(loc!=NULL)
         printf("node present");
         else
         {
             new1->next=graph;
             graph=new1;
         }
     }
 }


node* find(int inf)
{
      node*temp=graph;
     if(temp->nodeno==inf)
     return graph;
     else
     {
         while(temp!=NULL)
         {
                          if(temp->nodeno==inf)
                          return temp;
         }
         return temp;
     }
     
 }
 
void insert_egde()
{
     int src,dest;
     node *loc1,*loc2;
     printf("enter source:");
     scanf("%d",&src);
     printf("enter dest:");
     scanf("%d",&dest);
     loc1=find(src);
     loc2=find(dest);
     if(loc1==NULL || loc2==NULL)
     printf("egde not possible!");
     else
     {
         edge*new1;
         new1=(edge*)malloc(sizeof(edge));
         new1->next=loc1->link;
         new1->nodeno=dest;
         loc1->link=new1;
     }
}
  
void display()
{
     node *temp1=graph;
     edge *temp2;
     while(temp1!=NULL)
     {
                     temp2=temp1->link;
                     printf("%d    ",temp1->nodeno);
                     while(temp2!=NULL)
                     {
                                 printf("%d,",temp2->nodeno);      
                     }                    
                     printf("\n");
     }
}

Recommended Answers

All 11 Replies

What's this?.. another guess what's wrong with my code game... huh

Not only do you want us to do the work for you, but you did not state how your program works, it's purpose or the desired output.

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a cheater. 
    If you use that code [i]you[/i] are a cheater.
[*]Do [b]not[/b] bore us with how new you are. We can tell by your code.
- Do not apologize. We were all new, and unless you are completely 
  brain dead you will get better.
- Do not ask us to "take it easy on you."
- Do not say "I don't know what's going on." That's obvious since
  you posted for help. Use that time wisely by [b]explaining[/b] as best 
  you can so we can help.
[*][b]Do not post your requirements and nothing else. [/b]We view that as a lazy do-nothing student that wants us to do their work for them. That's cheating and we [i]will[/i] be hard on you.
[*]Do not attach files except when absolutely necessary. Most of us are not going to download file.  Add the information to your post.
[*][b]Do not tell us how urgent it is.[/b] Seriously, for us there is no urgency at all. Many that can help will ignore any URGENT or ASAP requests.
[/list]
Think more about your next post so we don't have to play 20 questions to get the info we need to help you.

[/boilerplate_help_info]

if u are getting any error in the code better focus that error so that we can try to solve it

if u are getting any error in the code better focus that error so that we can try to solve it

it is saying that "incompatible pointer conversion"

well friend its not showing any error here.
But there are some warnings.

it is saying that "incompatible pointer conversion"

Oh goody, a guessing game! The odds: 1:139 chance of guessing the correct line.

See this and read it this time.

You have to decide, is it egde or edge the name of your struct?

You have to decide, is it egde or edge the name of your struct?

ya, this is right answer. i got that.warning washed off. thnxx. thread is solved.

its really great to observe those small points
thanks for solving the error..

its really great to observe those small points
thanks for solving the error..

ya! all credit goes to www.daniweb.com .i have come to know since 3 months.this is damn awsum and fabulous site.

:) pleased to help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.