#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node* next;
};
struct node * root=NULL;
void display();
void delet();
void insert();
int main()
{
int ch;
while(1)
{
printf("1.delete at beginning\n");
printf("2.add element in link list\n");
printf("3.display element\n");
printf("4.exit\n");
printf("Enter your choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
delet();
break;
case 2:
insert();
break;
case 3:
display();
break;
case 4:
exit(1);
break;
default:
printf("Invalid choice\n");
}
}
}
void delet()
{
struct node * temp;
if(root==NULL)
printf("delete is not possible\n");
else
{
temp=root->next;
root=temp;
}
}
void display()
{
struct node * temp;
temp=root;
if(temp==NULL)
printf("List is Empty\n");
else
{
while(temp!=NULL)
{
printf("%d-->",temp->data);
temp=temp->next;
}
printf("NULL\n");
}
}
void insert()
{
struct node* temp;
temp=(struct node*)malloc(sizeof(struct node));
printf("Enter node data to add begin\n");
scanf("%d",&temp->data);
temp->next=NULL;
if(root==NULL)
root=temp;
else
{
temp->next=root;
root=temp;
}
}
0 Comments