Advertisement
apl-mhd

liknedList SIr

Mar 7th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. #include<stdio.h>
  2. struct list {
  3.         int data;
  4.         struct list *next;
  5. };
  6.  
  7. typedef struct list node;
  8.  
  9. node *copyHead;
  10.  
  11. void display(node *start)
  12. {
  13.     node *temp;
  14.     temp=start;
  15.     while(temp!=NULL)
  16.     {
  17.         printf("%d ",temp->data);
  18.         temp=temp->next;
  19.     }
  20. }
  21.  
  22.  
  23.  
  24.  
  25. int main()
  26. {
  27.     node *start=NULL,*temp, *head, *temp1, *prev, *copyHead;
  28.     int ans;
  29.     printf("Do You want to create node:");
  30.     scanf("%d",&ans);
  31.     while(ans==1)
  32.     {
  33.         if(start==NULL)
  34.         {
  35.             start=new node();
  36.  
  37.             printf("Enter your Data:");
  38.             scanf("%d",&start->data);
  39.             start->next=NULL;
  40.             prev=start;
  41.         }
  42.         else
  43.         {
  44.             temp=new node();
  45.             printf("Enter your Data:");
  46.             scanf("%d",&temp->data);
  47.             temp->next=NULL;
  48.             prev->next=temp;
  49.             prev=temp;
  50.  
  51.         }
  52.  
  53.         printf("Do You want to create node:");
  54.         scanf("%d",&ans);
  55.     }
  56.  
  57.     head = NULL;
  58.     temp = start;
  59.  
  60. /*
  61.     while(temp !=NULL){
  62.  
  63.         if(head == NULL){
  64.  
  65.             head = new node();
  66.             head->next = NULL;
  67.             head->data = temp->data;
  68.  
  69.         }
  70.  
  71.         else{
  72.             temp1 = new node();
  73.             temp1->next = head;
  74.             temp1->data = temp->data;
  75.             head->next= temp1;
  76.         }
  77.  
  78.  
  79.     }
  80. */
  81.  
  82.  
  83.  
  84.     display(start);
  85.     display(copyHead);
  86.  
  87.  
  88.  
  89. return 0;
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement