1. Doubly Linear Linked List
/***** @author: Er. Ganesh Ram Suwal *****/
/* Doubly Linked List */
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#include<process.h>
// Global variables
int data,position,i;
//Structure for Node
struct node
{
int info;
struct node *pnext,*pprev;
};
struct node *pthis, *pnew, *ptemp, *pfirst;
// Fubction Prototype
void nifb();
void nibxp();
void niaxp();
void nife();
void ndfb();
void ndfe();
void ndfsp();
void display();
void newNode()
{
pnew = (struct node*)malloc(sizeof(struct node));
printf("Data : ");
scanf("%d",&data);
pnew->info = data;
}
void invalidPosition()
{
printf("n****************************************************n");
printf(" Invalid Position! Try Again ");
printf("n****************************************************n");
}
// Counting the nodes of Linked List
int length()
{
int count = 0;
if(pfirst == NULL)
{
return 0;
}
else
{
pthis = pfirst;
count = 1;
while(pthis->pnext != NULL)
{
pthis = pthis->pnext;
2. Doubly Linear Linked List
count = count + 1;
}
return count;
}
}
// Main program function
void main()
{
clrscr();
int choice;
start:
printf("n********* Doubly Linked List *******************n");
printf("1: Node insertion from the beginingn");
printf("2: Node insertion from the endn");
printf("3: Node insertion before Xth positionn");
printf("4: Node insertion after Xth positionn");
printf("5: Node Delete from the begining n");
printf("6: Node Delete from the endn");
printf("7: Node delete from specified positionn");
printf("8: Displayn");
printf("9: Exitn");
printf("Enter your choice :");
scanf("%d",&choice);
switch(choice)
{
case 1:nifb();
break;
case 2:nife();
break;
case 3:nibxp();
break;
case 4:niaxp();
break;
case 5:ndfb();
break;
case 6:ndfe();
break;
case 7:ndfsp();
break;
case 8:display();
break;
case 9:exit(0);
break;
default: printf("Invalid Choice");
break;
}
goto start;
}
// Node Insertion from the begining
void nifb()
{
newNode();
pnew->pprev = NULL;
if(pfirst == NULL)
{
pnew->pnext = NULL;
pfirst = pnew;