what is the problem with this
it is printing only the first node data :( .some one pls help me...
#include<stdio.h>
#include<stdlib.h>
struct node
{
struct node *prev,*next;
int data;
};
void create_list(struct node *list,int n)
{
struct node *n1,*n2;
int i;
n1=list;
printf("enter the data for the 1 node:");
scanf("%d",&list->data);
for(i=1;i<n;i++)
{
list->next=(struct node *)malloc(sizeof(struct node));
if(list->next==NULL)
{
printf("malloc not done");
exit(0);
}
n2=list;
list=list->next;
list->prev=n2;
printf("enter the data for the %d node",i+1);
scanf("%d",&list->data);
}
list->next=n1;
n1->prev=list;
}
void print_list(struct node *list)
{
struct node *temp;
temp=list;
if(list->next=temp)
{
printf("%d",list->data);
}
if(list->next!=temp)
{
printf("%d",list->data);
if(list->next->next==temp)
printf("%d",list->next->data);
else
print_list(list->next);
}
}
int main()
{
int n;
struct node *head;
head=(struct node *)malloc(sizeof(struct node));
if(head==NULL)
{
printf("space unallocated");
exit (0);
}
printf("enter the no of nodes:");
scanf("%d",&n);
create_list(head,n);
print_list(head);
return 0;
}