Advertisement
Guest User

readNumbersList

a guest
Nov 18th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. typedef struct NODE {
  5.     int data;
  6.     struct NODE *next;
  7. }NODE;
  8.  
  9. NODE *makeNode(int key) {
  10.     NODE *node = (NODE *)malloc(sizeof(NODE));
  11.     if (!node)
  12.         return NULL;
  13.     node->data = key;
  14.     node->next = NULL;
  15.     return node;
  16. }
  17.  
  18. void addLast(NODE *head, NODE *temp) {
  19.     NODE *current = head;
  20.     while (current->next != NULL)
  21.         current = current->next;
  22.     current->next = temp;
  23. }
  24.  
  25. void main() {
  26.     int i, num;
  27.     printf("Enter number for head: ");
  28.     scanf_s("%d", &num);
  29.     NODE *head = makeNode(num);
  30.  
  31.     for (i = 0; i < 3; i++) {
  32.         printf("Enter Number: ");
  33.         scanf("%d", &num);
  34.         NODE *temp = makeNode(num);
  35.         addLast(head, temp);
  36.     }
  37.     while (head)
  38.     {
  39.         printf("%d", head->data);
  40.         head = head->next;
  41.     }  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement