fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct linkedlist{
  4. int data;
  5. struct linkedlist *next;
  6. };
  7. typedef struct linkedlist *node;
  8. void insert(node* head,int t)
  9. {
  10. node *o,*p,*q;
  11. o=*head;
  12. int n;
  13. scanf("%d",&n);
  14. while(t--)
  15. {
  16.  
  17. p=&(*o)->next;
  18. o=&(*o)->next;
  19.  
  20.  
  21. }
  22. *q=(node)malloc(sizeof(struct linkedlist));
  23. *q->data=n;
  24.  
  25.  
  26.  
  27. *o->next=*q;
  28. *p=*q->next;
  29. *q=*o->next;
  30.  
  31.  
  32.  
  33. }
  34. void search(node head, int n)
  35. {
  36. node i;
  37. i=head;
  38. while(i!=NULL)
  39. {
  40. if(i->data==n)
  41. {printf("%d\n",i->data);
  42. break;}
  43.  
  44. i=i->next;
  45.  
  46.  
  47. }
  48.  
  49. }
  50. void printvalue(node head)
  51. {
  52. node current;
  53. current=head;
  54. while(current!=NULL)
  55. {
  56. printf("%d\n",current->data);
  57. current=current->next;
  58. }
  59. }
  60.  
  61. int main()
  62. {
  63. int n,p,t;
  64. scanf("%d\n",&n);
  65. node head;
  66. head=NULL;
  67. head=(node)malloc(sizeof(struct linkedlist));
  68.  
  69. if(head==NULL)
  70. {return 0;}
  71. node temp=head;
  72. for(int i=0;i<n;i++)
  73. {
  74.  
  75. if(i<n-1)
  76. {
  77.  
  78. int k;
  79. scanf("%d\n",&k);
  80. temp->data=k;
  81. temp->next=(node)malloc(sizeof(struct linkedlist));
  82. temp=temp->next;
  83.  
  84. }
  85. else
  86. {
  87. int k;
  88. scanf("%d\n",&k);
  89. temp->data=k;
  90. temp->next=(node)malloc(sizeof(struct linkedlist));
  91.  
  92. temp->next=NULL;
  93.  
  94. }
  95.  
  96.  
  97. }
  98. printf("\n");
  99. //printvalue(head);//
  100. scanf("%d\n",&p);
  101. search(head, p);
  102. scanf("%d\n",&t);
  103. insert(&head,t);
  104. printvalue(head);
  105. return 0;
  106.  
  107.  
  108. }
Compilation error #stdin compilation error #stdout 0s 9424KB
stdin
5
1
2
3
4
5
3
3
7
compilation info
prog.c: In function ‘insert’:
prog.c:11:10: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
         o=*head;
          ^
prog.c:23:11: error: ‘*q’ is a pointer; did you mean to use ‘->’?
         *q->data=n;
           ^~
           ->
prog.c:27:11: error: ‘*o’ is a pointer; did you mean to use ‘->’?
         *o->next=*q;
           ^~
           ->
prog.c:28:14: error: ‘*q’ is a pointer; did you mean to use ‘->’?
         *p=*q->next;
              ^~
              ->
prog.c:29:14: error: ‘*o’ is a pointer; did you mean to use ‘->’?
         *q=*o->next;
              ^~
              ->
stdout
Standard output is empty