Advertisement
pkbagchi

insert_data(reverse)

Nov 6th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct node {
  5.     int data;
  6.     struct node *next;
  7. };
  8.  
  9. struct node* head = NULL;
  10. void insert(int n) {
  11.     struct node*temp;
  12.     temp = (struct node*)malloc(sizeof(struct node));
  13.     temp->data = n;
  14.     temp->next = head;
  15.     head = temp;
  16.  
  17. }
  18. void print() {
  19.     struct node* temp;
  20.     temp = head;
  21.     while(temp != NULL) {
  22.         printf("%d\t" , temp->data);
  23.         temp = temp->next;
  24.     }
  25. }
  26. int main ()
  27. {
  28.     int x, m, n;
  29.     scanf("%d" , &m);
  30.     for(x = 1; x <= m; x++) {
  31.         scanf("%d" , &n);
  32.         insert(n);
  33.     }
  34.     print();
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement