#include<stdio.h>
#include<stdlib.h>
typedef struct{
int key;
struct node *next;
}node;
node *head,*tail;
void init_node(void)
{
head=(node*)malloc(sizeof(node));
tail=(node*)malloc(sizeof(node));
head->next=tail;
tail->next=tail;
}
node *inputn(node *h)
{
int a;
node *s;
s=(node*)malloc(sizeof(node));
printf("Input Key Data :");
scanf("%d",&a);
s->key=a;
s->next=h->next;
h->next=s;
return s;
}
void deln(node *h)
{
int b;
node *i;
i=(node*)malloc(sizeof(node));
printf("Input Del data :");
scanf("%d",&b);
i=h->next;
while(i->key != b && i != tail)
{
h=i;
i=i->next;
}
if(i != tail)
{
h->next=i->next;
free(i);
}
}
void prtn(node *h)
{
while(h->next != tail)
{
h=h->next;
printf("%d\t",h->key);
}
}
void adeln(node *h)
{
while(h->next != tail)
{
node *u;
u=(node*)malloc(sizeof(node));
u=h->next;
h->next=u->next;
free(u);
}
}
void main()
{
int c;
init_node();
while(1)
{
printf("\n1. Input node\n");
printf("2. Delete node\n");
printf("3. Print node \n");
printf("4. All node delete\n");
printf("5. Exit The Program\n");
scanf("%d",&c);
switch(c)
{
case 1:
{
inputn(head);
break;
}
case 2:
{
deln(head);
break;
}
case 3:
{
prtn(head);
break;
}
case 4:
{
adeln(head);
break;
}
case 5:
{
adeln(head);
free(head);
free(tail);
exit(0);
}
}
}
}