fork download
  1. #include <stdio.h>
  2.  
  3. struct node
  4. {
  5. int data;
  6. struct node *next;
  7. };
  8. struct node *head=NULL;
  9.  
  10.  
  11. void main()
  12. {
  13. struct node *temp;
  14. int ch,a,ch1,ch2;
  15. head=NULL;
  16.  
  17. do
  18. {
  19. printf("1:insert,2:delete,3:reverse,4:display");
  20. scanf("%d",&ch);
  21.  
  22. switch(ch)
  23. {
  24. case 1:printf("1:beg,2:end,3:middle");
  25. scanf("%d",ch1);
  26.  
  27. if(ch1==1)
  28. {
  29. head=insert_beg(head);
  30.  
  31. }
  32. else if(ch1==2)
  33. {
  34. head=insert_end(head);
  35. }
  36. else if(ch1==3)
  37. {
  38. printf("enter data after which you want to enter");
  39. scanf("%d",&a);
  40.  
  41. head=insert_mid(head,a);
  42. }break;
  43. case 2:printf("1:beg,2:end,3:mid");
  44. scanf("%d",&ch2);
  45. if(ch2==1)
  46. {
  47. head=delete_beg(head);
  48. }
  49. else if(ch2==2)
  50. {
  51. head=delete_end(head);
  52. }
  53. else if(ch2==3)
  54. {
  55. printf("enter data after whcich you want to enter");
  56. scanf("%d",&a);
  57. head=delete_mid(head,a);
  58. }break;
  59. case 3:
  60. head=reverse(head);
  61. break;
  62. case 4:
  63. display(head);
  64. break;
  65.  
  66.  
  67. }
  68. }while(1);
  69. }
  70.  
  71. struct node *create(struct node *p)
  72. {
  73. int x;
  74. p=(struct node*)malloc(sizeof(struct node));
  75. printf("enter the data");
  76. scanf("%d",&x);
  77. p->data=x;
  78. p->next=NULL;
  79. return(p);
  80. }
  81.  
  82. struct node *insert_mid(struct node *head,int a)
  83. {
  84. struct node *temp,*p;
  85. p=head;
  86. temp=create(p);
  87.  
  88. if(head==NULL)
  89. {
  90. head=temp;
  91. }
  92. else
  93. {
  94. while(p->data!=a)
  95. {
  96. p=p->next;
  97. }
  98. temp->next=p->next;
  99. p->next=temp;
  100. }
  101.  
  102.  
  103. return head;
  104.  
  105.  
  106.  
  107. struct node *delete_mid(struct node *head,int a)
  108. {
  109. struct node *temp,*p,*r;
  110. p=head;
  111. if(head==NULL)
  112. {
  113. printf("data cannot be deleted");
  114. }
  115. {
  116. else
  117. while(p->data!=a)
  118. {
  119. r=p;
  120. p=p->next;
  121. }
  122. r->next=p->next;
  123. }
  124. }
  125. return head;
  126.  
  127.  
  128. struct node *insert_beg(struct node *head)
  129. {
  130. struct node *temp;
  131. temp=create(p);
  132. if(head==NULL)
  133. {
  134. head=temp;
  135.  
  136. }
  137. else
  138. {
  139.  
  140. temp->next=head;
  141. head=temp;
  142. }
  143. return head;
  144.  
  145. struct node *insert_end(struct node *head)
  146. {
  147. struct node *temp,*p;
  148. p=head;
  149. temp=create(p);
  150. if(head==NULL)
  151. {
  152. head=temp;
  153.  
  154. }
  155. else
  156. {
  157. while(p->next!=NULL)
  158. {
  159.  
  160. p=p->next;
  161. }
  162. p->next=temp;
  163. }
  164. }
  165. return head;
  166.  
  167.  
  168.  
  169. struct node *delete_beg(struct node *head)
  170. {
  171. struct node *p;
  172. p=head;
  173. if(head==NULL)
  174. {
  175. printf("data cannot be deleted");
  176. }
  177. {
  178. else
  179. {
  180. head=p->next;
  181. free(p);
  182. printf("data deleted");
  183. }
  184. return head;
  185.  
  186.  
  187. struct node *delete_end(struct node *head,int a)
  188. {
  189. struct node *p,*r;
  190. p=head;
  191. if(head==NULL)
  192. {
  193. printf("data cannot be deleted");
  194. }
  195. {
  196. elsele(p->next!=NULL)
  197. {
  198. r=p;
  199. p=p->next;
  200. }
  201. r->next=NULL;
  202. }
  203. }
  204. return head;
  205.  
  206.  
  207.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:11:6: warning: return type of 'main' is not 'int' [-Wmain]
 void main()
      ^
prog.c: In function 'main':
prog.c:25:19: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'int' [-Wformat=]
             scanf("%d",ch1);
                   ^
prog.c:29:22: warning: implicit declaration of function 'insert_beg' [-Wimplicit-function-declaration]
                 head=insert_beg(head);
                      ^
prog.c:29:21: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
                 head=insert_beg(head);
                     ^
prog.c:34:18: warning: implicit declaration of function 'insert_end' [-Wimplicit-function-declaration]
             head=insert_end(head);
                  ^
prog.c:34:17: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
             head=insert_end(head);
                 ^
prog.c:41:18: warning: implicit declaration of function 'insert_mid' [-Wimplicit-function-declaration]
             head=insert_mid(head,a);
                  ^
prog.c:41:17: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
             head=insert_mid(head,a);
                 ^
prog.c:47:23: warning: implicit declaration of function 'delete_beg' [-Wimplicit-function-declaration]
                  head=delete_beg(head);
                       ^
prog.c:47:22: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
                  head=delete_beg(head);
                      ^
prog.c:51:18: warning: implicit declaration of function 'delete_end' [-Wimplicit-function-declaration]
             head=delete_end(head);
                  ^
prog.c:51:17: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
             head=delete_end(head);
                 ^
prog.c:57:18: warning: implicit declaration of function 'delete_mid' [-Wimplicit-function-declaration]
             head=delete_mid(head,a);
                  ^
prog.c:57:17: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
             head=delete_mid(head,a);
                 ^
prog.c:60:18: warning: implicit declaration of function 'reverse' [-Wimplicit-function-declaration]
             head=reverse(head);
                  ^
prog.c:60:17: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
             head=reverse(head);
                 ^
prog.c:63:13: warning: implicit declaration of function 'display' [-Wimplicit-function-declaration]
             display(head);
             ^
prog.c:13:18: warning: unused variable 'temp' [-Wunused-variable]
     struct node *temp;
                  ^
prog.c: In function 'create':
prog.c:74:25: warning: implicit declaration of function 'malloc' [-Wimplicit-function-declaration]
         p=(struct node*)malloc(sizeof(struct node));
                         ^
prog.c:74:25: warning: incompatible implicit declaration of built-in function 'malloc'
prog.c:74:25: note: include '<stdlib.h>' or provide a declaration of 'malloc'
prog.c: At top level:
prog.c:82:18: error: conflicting types for 'insert_mid'
     struct node *insert_mid(struct node *head,int a)
                  ^
prog.c:41:18: note: previous implicit declaration of 'insert_mid' was here
             head=insert_mid(head,a);
                  ^
prog.c: In function 'delete_mid':
prog.c:116:9: error: 'else' without a previous 'if'
         else
         ^
prog.c:109:22: warning: unused variable 'temp' [-Wunused-variable]
         struct node *temp,*p,*r;
                      ^
prog.c:124:5: warning: no return statement in function returning non-void [-Wreturn-type]
     }
     ^
prog.c: In function 'insert_end':
prog.c:164:5: warning: no return statement in function returning non-void [-Wreturn-type]
     }
     ^
prog.c: In function 'delete_beg':
prog.c:178:9: error: 'else' without a previous 'if'
         else
         ^
prog.c:181:12: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
            free(p);
            ^
prog.c:181:12: warning: incompatible implicit declaration of built-in function 'free'
prog.c:181:12: note: include '<stdlib.h>' or provide a declaration of 'free'
prog.c: In function 'delete_end':
prog.c:196:9: warning: implicit declaration of function 'elsele' [-Wimplicit-function-declaration]
         elsele(p->next!=NULL)
         ^
prog.c:197:9: error: expected ';' before '{' token
         {
         ^
prog.c:189:25: warning: unused variable 'r' [-Wunused-variable]
         struct node *p,*r;
                         ^
prog.c:203:5: warning: no return statement in function returning non-void [-Wreturn-type]
     }
     ^
prog.c: In function 'delete_beg':
prog.c:204:8: error: expected declaration or statement at end of input
        return head;
        ^
prog.c:204:8: error: expected declaration or statement at end of input
prog.c: In function 'insert_beg':
prog.c:204:8: error: expected declaration or statement at end of input
prog.c: In function 'insert_mid':
prog.c:204:8: error: expected declaration or statement at end of input
stdout
Standard output is empty