Niloy007

Sumaia's Code

Nov 28th, 2020
500
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. struct node {
  4.     int data;
  5.     struct node *next;
  6. };
  7.  
  8. typedef struct node NODE;
  9. struct node *head = new NODE();
  10.  
  11. void insert() {
  12.     struct node *temp = new struct node();
  13.  
  14.     if(head->next == NULL) {
  15.         int x;
  16.         printf("Enter number:\n");
  17.         scanf("%d", &x);
  18.         temp->data = x;
  19.         temp->next = NULL;
  20.         head->next = temp;
  21.     } else {
  22.         temp = head;
  23.         NODE *flag = new NODE();
  24.         while (temp->next != NULL) {
  25.             temp = temp->next;
  26.         }
  27.  
  28.         int x;
  29.         printf("Enter number:\n");
  30.         scanf("%d", &x);
  31.         flag->data = x;
  32.         flag->next = NULL;
  33.         temp->next = flag;
  34.     }
  35. }
  36.  
  37. void display() {
  38.     NODE *temp = head;
  39.     while(temp->next != NULL) {
  40.         printf("%d ", temp->next->data);
  41.         temp = temp->next;
  42.     }
  43.     printf("\n");
  44. }
  45.  
  46. int main() {
  47.    
  48.     insert();
  49.     insert();
  50.     display();
  51.  
  52. }
RAW Paste Data