#include <conio.h>
#include <malloc.h>
struct node
{
int data;
node *link;
}
node *front = NULL;
node *rear = NULL;
void insertion
{
node *temp = (node*) malloc (sizeof(node));
printf ("Input Elements");
scanf ("%d",&temp->data);
if (front==NULL)
{
front = temp;
rear = temp;
}
else
{
int pick;
printf ("1.Front\n2.Rear\n3.Position");
scanf ("%d",&pick);
switch (pick)
{
case 1:
temp->link = front;
front = temp;
break;
case 2:
rear->link = temp;
rear = temp;
rear->link = NULL;
break;
case 3:
int pos;
printf ("Insert Position");
scanf ("%d",&pos);
if (pos<1)
{
printf ("error");
}
else if (pos==1)
{
temp->link = front;
front = temp;
}
else
{
pos--;
int count=1;
node *trav;
trav = front;
while (count<pos && trav!=NULL)
{
count ++;
trav=trav->link;
}
if (trav!=NULL)
{
temp->link=trav->link;
trav->link=temp;
if (rear->link!=NULL)
{
rear=temp;
}
}
else
{
printf ("error");
}
}
break;
}
}
}