Guest User

Untitled

a guest
Jan 7th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct Node
  4. {
  5.     int data;
  6.     struct Node *link;
  7. };
  8.  
  9. int main()
  10. {
  11.   struct Node nodes[50];
  12.   struct Node *head = &nodes[0];
  13.   struct Node *tail = head;
  14.   int num_nodes_used = 1;
  15.  
  16.     int number = 0;
  17.  
  18.     do{
  19.         printf("node # %d > ", num_nodes_used);
  20.         fflush(stdout);
  21.         scanf("%d", &number);
  22.         if(number){
  23.         tail->data = number;
  24.         tail->link = &nodes[num_nodes_used++];
  25.         printf("Tail data is %d\nTail address is%x\n", tail->data, tail);
  26.         tail = tail->link;
  27.         }
  28.         tail->link = NULL;
  29.     }while (number != 0);
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment