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<stdio.h> #include<conio.h> #include<stdlib.h> 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); }
0