#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *link;
};
struct node *head,*lhead;
struct node *newnode=NULL;
struct node *node1=NULL;
struct node *node2=NULL;
struct node *node3=NULL;
void insert();
void insert1();
void insert2();
void display();
void main()
{
int ch;
clrscr();
do
{
printf("\n\n\t\t LINK LIST IMPLEMENTATION \n ");
printf("\n\n 1. Insert _ From Beging ");
printf("\n 2. Insert _ From last ");
printf("\n 3. Insert _ From Middle ");
printf("\n 4. Display ");
printf("\n 5. Exit.... ");
printf("\n\n => Enter The Choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
insert1();
break;
case 3:
insert2();
break;
case 4:
display();
break;
default:printf("\n Wrong Choice.....! ");
}
getch();
clrscr();
}while(ch!=5);
}
void insert()
{
int element;
node1=(struct node*)malloc(sizeof(struct node));
node2=(struct node*)malloc(sizeof(struct node));
node3=(struct node*)malloc(sizeof(struct node));
newnode=(struct node*)malloc(sizeof(struct node));
printf("\nEnter The Element Frome Begning :");
scanf("%d",&element);
newnode->data=element;
node1->data=10;
node2->data=20;
node3->data=30;
node1->link=node2;
node2->link=node3;
node3->link=NULL;
head=node1;
lhead=node3;
newnode->link=head;
head=newnode;
}
void insert1()
{
struct node *temp=head;
struct node *newnode=NULL;
int element;
newnode=(struct node*)malloc(sizeof(struct node));
printf("\nEnter The Element Frome Last:");
scanf("%d",&element);
newnode->data=element;
while(temp!=NULL)
{
temp=temp->link;
}
lhead->link=newnode;
newnode->link=temp;
}
void insert2()
{
struct node *temp;
struct node *newnode=NULL;
int i,position,element;
temp=head;
newnode=(struct node*)malloc(sizeof(struct node));
printf("\n Enter The Possition :");
scanf("%d",&position);
printf("\n\NEnter The Element Frome Begning :");
scanf("%d",&element);
newnode->data=element;
for(i=2;i<position;i++)
{
temp=temp->link;
}
newnode->link=temp->link;
temp->link=newnode;
}
void display()
{
struct node *temp;
temp=head;
while(temp!=NULL)
{
printf("\n%d",temp->data);
temp=temp->link;
}
}