Sunday, 27 November 2016

Doubly linked list - IMPLIMENTATION

Tags

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node{
int data;
struct node*next;
struct node*prev;
}*head;
void addbeg(int x)
{
struct node*temp;
temp=(struct node*)malloc(sizeof(struct node));
temp->data=x;
temp->prev=NULL;
temp->next=head;
if(head!=NULL)
{
head->prev=temp;
}
head=temp;
}
void print()
{
struct node*temp;
temp=head;
printf("\n list is:\n");
while(temp!=NULL)
{
printf("%d",temp->data);
temp=temp->next;
}
printf("\n");
}
void main( )
{
head=NULL;
printf("\n how many numbers?\n");
int n,i,x;
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n enter the number");
scanf("%d",&n);
addbeg(x);
print();
}
}
getch();