/* Program of single linked list with n integers
displayed in 4 seperate Lists */
# include <stdio.h>
# include <malloc.h>
# include <conio.h>
struct node
{
int info;
struct node *link;
}*start,*list1,*list2,*list3,*list4;
void main()
{
int choice,n,m,position,i;
int c1=0,c2=1,c3=2,c4=3;
list1=NULL;
list2=NULL;
list3=NULL;
list4=NULL;
while(1)
{ clrscr();
printf("\n\n");
printf("\n\n0.Create List");
printf("\n\n1.Display 1st List");
printf("\n\n2.Display 2nd List");
printf("\n\n3.Display 3rd List");
printf("\n\n4.Display 4th List");
printf("\n\n5.Quit");
printf("\n\n\nEnter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 0:
printf("How many nodes you want : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
if(i==c1)
{
printf("Enter the element : ");
scanf("%d",&m);
create_list1(m);
c1=c1+4;
}
if(i==c2)
{
printf("Enter the element : ");
scanf("%d",&m);
create_list2(m);
c2=c2+4;
}
if(i==c3)
{
printf("Enter the element : ");
scanf("%d",&m);
create_list3(m);
c3=c3+4;
}
if(i==c4)
{
printf("Enter the element : ");
scanf("%d",&m);
create_list4(m);
c4=c4+4;
}
} // End of For Loop
break;
case 1:display1();
break;
case 2:
display2();
break;
case 3:display3();
break;
case 4:display4();
break;
case 5:exit();
break;
default:
printf("Wrong choice\n");
}/*End of switch */
}/*End of while */
}/*End of main()*/
create_list1(int data)
{
struct node *q,*tmp;
tmp= malloc(sizeof(struct node));
tmp->info=data;
tmp->link=NULL;
if(list1==NULL) /*If list is empty */
list1=tmp;
else
{ /*Element inserted at the end */
q=list1;
while(q->link!=NULL)
q=q->link;
q->link=tmp;
}
}/*End of create_list1()*/
create_list2(int data)
{
struct node *q,*tmp;
tmp= malloc(sizeof(struct node));
tmp->info=data;
tmp->link=NULL;
if(list2==NULL) /*If list is empty */
list2=tmp;
else
{ /*Element inserted at the end */
q=list2;
while(q->link!=NULL)
q=q->link;
q->link=tmp;
}
}/*End of create_list2()*/
create_list3(int data)
{
struct node *q,*tmp;
tmp= malloc(sizeof(struct node));
tmp->info=data;
tmp->link=NULL;
if(list3==NULL) /*If list is empty */
list3=tmp;
else
{ /*Element inserted at the end */
q=list3;
while(q->link!=NULL)
q=q->link;
q->link=tmp;
}
}/*End of create_list3()*/
create_list4(int data)
{
struct node *q,*tmp;
tmp= malloc(sizeof(struct node));
tmp->info=data;
tmp->link=NULL;
if(list4==NULL) /*If list is empty */
list4=tmp;
else
{ /*Element inserted at the end */
q=list4;
while(q->link!=NULL)
q=q->link;
q->link=tmp;
}
}/*End of create_list4()*/
display1()
{
struct node *q;
if(list1 == NULL)
{
printf("List is empty\n");
return;
}
q=list1;
printf("List is :\n");
while(q!=NULL)
{
printf("%d ", q->info);
q=q->link;
}
printf("\n");
getch();
}/*End of display1() */
display2()
{
struct node *q;
if(list2 == NULL)
{
printf("List is empty\n");
return;
}
q=list2;
printf("List is :\n");
while(q!=NULL)
{
printf("%d ", q->info);
q=q->link;
}
printf("\n");
getch();
}/*End of display2() */
display3()
{
struct node *q;
if(list3 == NULL)
{
printf("List is empty\n");
return;
}
q=list3;
printf("List is :\n");
while(q!=NULL)
{
printf("%d ", q->info);
q=q->link;
}
printf("\n");
getch();
}/*End of display3() */
display4()
{
struct node *q;
if(list4 == NULL)
{
printf("List is empty\n");
return;
}
q=list4;
printf("List is :\n");
while(q!=NULL)
{
printf("%d ", q->info);
q=q->link;
}
printf("\n");
getch();
}/*End of display4() */