#include <stdio.h>
struct node
{
int data;
struct node *next;
struct node *prev;
};
int addnode(int n)
{
struct node *temp,*current,*head;
current=(struct node*)malloc(sizeof(struct node));
head=current;
while(1)
{
if(n!=0)
{
current->data=n;
temp=current;
current=(struct node*)malloc(sizeof(struct node));
temp->next=current;
current->prev=temp;
printf("Enter Number [0 to terminate]=");
scanf("%d",&n);
}
else
{
temp->next=NULL;
break;
}
}
return head;
}
int print(struct node *head)
{
struct node *temp;
temp=head;
while(temp!=NULL)
{
printf("%10d%10d%10d%10d\n",temp->prev,temp,temp->data,temp->next);
temp=temp->next;
}
}
int main()
{
int n;
struct node *head;
printf("Enter Number=");
scanf("%d",&n);
head=addnode(n);
print(head);
}
0 comments:
Post a Comment