fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct node
  4. {
  5. int data;
  6. struct node *next,*prev;
  7. };
  8. struct node *head,*shead,*temp,*temp1;
  9. int main(void){
  10. int c=1;
  11.  
  12. while(c)
  13. {
  14. temp = malloc(sizeof(struct node));
  15. printf("enter the data for the node\n");
  16. scanf("%d",&temp->data);
  17. if(head==NULL){
  18. head=temp;
  19. head->next=NULL;
  20. head->prev=NULL;
  21. shead = head;
  22. }
  23. else {
  24. shead->next=temp;
  25. temp->prev=shead;
  26. temp->next=NULL;
  27. shead = shead->next;
  28. }
  29. printf("for new node enter 1 otherwise 0\n");
  30. scanf("%d",&c);
  31.  
  32. }
  33. temp1=head;
  34. while(temp1!=NULL){
  35. printf("%d",temp1->data);
  36. temp1=temp1->next;
  37. }
  38.  
  39. }
Success #stdin #stdout 0s 4484KB
stdin
1 1 2 1 3 1 4 0
stdout
enter the data for the node
for new node enter 1 otherwise 0
enter the data for the node
for new node enter 1 otherwise 0
enter the data for the node
for new node enter 1 otherwise 0
enter the data for the node
for new node enter 1 otherwise 0
1234