error in a program

hey can anyone tell me my mistake in the foll program.I m not able to run the sorting part.i havent done merging part yet
#include
#include
#include
struct node
{
int data;
struct node *link;
}*temp,*head1,*newnode,*prev,*head2;
void main()
{
char option;
int pos,ch,cnt,x,t;
do
{
printf("\n linked list operations\n1.ceation of the first list\n2.creation of the second list\n3.sorting of the first list\n4.sorting of the second list\n5.merging of two list\n enter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
while(1)
{
printf("\n entere the data: ");
scanf("%d",&x);
newnode=(struct node*)malloc(sizeof(node));
newnode->link=NULL;
newnode->data=x;
if(head1==NULL)
   {
    head1=newnode;
    prev=newnode;
   }
else
   {
    prev->link=newnode;
    prev=newnode;
   }
printf("\n do u want to add another record(y//n): ");
scanf("%s",&option);
if(option=='n')
   {
    break;
   }
}
printf("\n the first list is: ");
prev=head1;
while(prev!=NULL)
      {
       printf("\t%d",prev->data);
       prev=prev->link;
      }
break;
case 2:
while(1)
{
printf("\n entere the data: ");
scanf("%d",&x);
newnode=(struct node*)malloc(sizeof(node));
newnode->link=NULL;
newnode->data=x;
if(head2==NULL)
   {
    head2=newnode;
    prev=newnode;
   }
else
   {
    prev->link=newnode;
    prev=newnode;
   }
printf("\n do u want to add another record(y//n): ");
scanf("%s",&option);
if(option=='n')
   {
    break;
   }
}
printf("\n the second list is: ");
prev=head2;
while(prev!=NULL)
      {
       printf("\t%d",prev->data);
       prev=prev->link;
      }
break;
case 3:
for(temp=head1;temp!=NULL;temp=temp->link)
    {
     prev=head1;
     while(prev!=NULL)
       {
          if(prev->data > prev->link->data)
            {
             t=prev->data;
             prev->data=prev->link->data;
             prev->link->data=t;
             prev=prev->link;
            }
        }
    }
printf("\n the sorted first list is: ");
prev=head1;
while(prev!=NULL)
      {
       printf("\t%d",prev->data);
       prev=prev->link;
      }
break;
case 4:
for(temp=head2;temp!=NULL;temp=temp->link)
    {
     for(prev=head2;prev!=NULL;prev=prev->link)
         {
          if(prev->data > prev->link->data)
            {
             t=prev->data;
             prev->data=prev->link->data;
             prev->link->data=t;
            }
        }
    }
printf("\n the sorted second list is: ");
prev=head2;
while(prev!=NULL)
      {
       printf("\t%d",prev->data);
       prev=prev->link;
      }
break;
}
}while(ch<6);
}

Replies

You are reading an archived discussion.

Related Posts

What Are the mail.Crazy Engineers.net POP3 and the SMTP Settings for Outlook Express to work with mail.Crazy Engineers.net
Which mail client(like outlook or thunderbird) is best one? Which is more secure? I want to know about opensource clients post your vote too..
i want to know what happens when a.c. current flows through semiconductor ,and what are its drawbacks. i learnt about skin effect, and want to know about any other considerable...
/www.electronic-circuits-diagrams.com/homegardenimages/1.gif
hello guys i am giving a link please read this article and give me your response ... do u think is it possible Get ready for fun - hardware interfacing...