fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct Node {
  5. int data;
  6. struct Node *next;
  7. } Node;
  8.  
  9.  
  10. Node *current[20];
  11.  
  12. void insert_beg_of_list(int data);
  13.  
  14. void print_list();
  15.  
  16.  
  17.  
  18. void insert_beg_of_list(int data) {
  19.  
  20.  
  21. /*First create a new node head */
  22. Node *head;
  23. head=(Node*)malloc(sizeof(Node));
  24. head->data=data;
  25. head->next=current[0];
  26. current[0]=head;
  27. }
  28.  
  29.  
  30.  
  31. void print_list() {
  32.  
  33.  
  34. Node *temp;
  35. temp=current[0];
  36. while(temp!=NULL)
  37. {
  38. printf("%d ",temp->data);
  39. temp=temp->next;
  40. }
  41. }
  42.  
  43.  
  44.  
  45. int main() {
  46.  
  47.  
  48. int data = 0 ;
  49. int usr_input = 0;
  50. int i;
  51. int m;
  52. int j;
  53.  
  54. scanf("%d", &usr_input);
  55.  
  56. current[0]=NULL;
  57. for (i=0; i<usr_input; i++) {
  58.  
  59. scanf("%d", &data);
  60. insert_beg_of_list(data);
  61.  
  62. }
  63.  
  64. printf("The list is ");
  65. print_list();
  66. printf("\n\n");
  67.  
  68. return 0;
  69. }
Success #stdin #stdout 0s 10320KB
stdin
5
14 15 78 96 54
stdout
The list is 54 96 78 15 14