Sunday 27 November 2011

C Program For Double Link List


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
   struct list
    {
 int data;
 struct list*next,*pri;
};
void main()
{
  struct list*temp,*start,*node;
  start=node=temp=null;
  int ch,pos;
  clrscr();
  do{
      printf("1.add 2.create first node 3.create middle node 4.display 5.exit");
 scanf("%d",&ch);
 if(ch == 1)
 {
   node=(struct list*)malloc(size of struct list);
scanf("%d",&node->data);
if(start == null)
{
start = node;
start = next = null;
start = pre = null;
}
else
temp = start;
while(temp->next!null)
 {
   temp=temp->next;
 }
  }
  if(ch == 2)
  {
   node=(struct list*)malloc(size of (struct list));
scamf("%d",&node->data);
start->pre=null;
start=next=null;
  }
 if(ch == 3)
 {
   printf("enter position");
scanf("%d",&pos);
node=(struct list*)malloc(size of(struct list));
scanf("%d",&node->data);
int e=0;
for(temp=start;temp!=null;temp=temp->next)
{
 e++;
 if(e == pos-1)
 break:
}
temp->next->pre->node;
node->next=temp->next;
node->pre=temp;
temp->next=node;
 }
 if(ch == 4)
 {
  for(temp=start;temp!null;temp=temp->next)
 printf("%d",temp->data);
 }
 if(ch == 5)
  exit(0);
}while(1);
getch();

}


No comments:

Post a Comment