#include<stdio.h>
#include<malloc.h>
typedef struct list
{
int data;
struct list *next;
}node;
node *START=NULL;
insert()
{
int i;
node *tmp,*q;
tmp=(node*)malloc(sizeof(node));
printf("\nEnter Element :: ");
scanf("%d",&i);
tmp->next=NULL;
tmp->data=i;
if(START==NULL)
{
START=tmp;
}else
{
q=START;
while(q->next!=NULL)
{
q=q->next;
}
q->next=tmp;
}
}
display()
{
node *q;
if(START==NULL)
{
printf("\nList Is Empty");
}else{
q=START;
while(q!=NULL)
{
printf("%d -> ",q->data);
q=q->next;
}
}
}
reverse()
{
node *p1,*p2,*p3;
int d;
if(START==NULL)
{
printf("\nThis Opetation Is Not Possible Due to Lack of Elements");
}
else
{
p1=START;
p2=p1->next;
p3=p2->next;
p1->next=NULL;
p2->next=p1;
while(p3!=NULL)
{
p1=p2;
p2=p3;
p3=p3->next;
p2->next=p1;
}
START=p2;
}
}
int main()
{
int ch,f=0;
//clrscr();//Optional
while(f<=1)
{
printf("\n1. INSERT VALUE\n2. DISPLAY \n3. REVERSE");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
//getch(); //Optional
break;
case 2:
display();
//getch();//Optional
break;
case 3:
reverse();
printf("\nOperation Done...");
break;
default:
printf("\nWrong Input");
}
}
}
Comments
Post a Comment