Advertisement
sujonshekh

Avail link 26-3-2017

Apr 10th, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct node
  4. {
  5. int a;
  6. struct node *p;
  7. };
  8. int count(struct node *head);
  9. void Display(struct node *head);
  10. void Insertion_last_position(struct node *head, int value);
  11. void Insertion_specific_position(struct node*head,int vv, int pp);
  12. void Deletion_specific_position(struct node*head, int pp);
  13. void Linear_search(struct node*head,int vv);
  14. int main()
  15. {
  16. int n,i,c,pos,v,q;
  17. struct node *list;
  18.  
  19. list=(struct node *)malloc(1*sizeof(struct node));
  20. list-> a=0;
  21. list-> p=NULL;
  22.  
  23. while(1)
  24. {
  25. printf("\n !!!....Menu....!!!\n");
  26. printf("\n press 1 for Insertion \n");
  27. printf("\n press 2 for Insertion specific position \n");
  28. printf("\n press 3 Display\n");
  29. printf("\n press 4 Deletion Spacific positin\n");
  30. printf("\n press 5 Count Total node\n");
  31. printf("\n press 6 Linear Search \n");
  32.  
  33. printf("\n Enter your choise \n");
  34. scanf("%d",&c);
  35. switch(c)
  36. {
  37. case 0:exit (0);
  38. break;
  39. case 1:printf("\n choice=Insertion at Last position");
  40. printf("\n Enter New value\n");
  41. scanf("%d",&v);
  42. Insertion_last_position(list,v);
  43. break;
  44.  
  45. case 2: printf("\n choice=Insertion at Specific position\n");
  46. n=count(list);
  47. if(n!=0)
  48. {
  49. K:printf("\n Enter Position between %d to %d\n",1,n+1);
  50. scanf("%d",&pos);
  51. if (pos>=1 && pos<=n+1)
  52. {
  53. printf("\n Enter New Value\n");
  54. scanf("%d",&v);
  55. Insertion_specific_position(list,v,pos);
  56.  
  57. }
  58. else
  59. printf("\n Wrong Position\n\n");
  60. break;
  61. }
  62. case 3: printf("\n choice=Display\n");
  63. if(list->p!=NULL)
  64. Display(list);
  65. else
  66. printf("\n list is Empty \n");
  67. break;
  68.  
  69. case 4: printf("\n choice=Deletion from specific position\n");
  70. n=count(list);
  71. if(n!=0)
  72. {
  73. L: printf ("\n Enter Position Between %d to %d\n",1,n);
  74. scanf("%d", & pos);
  75. if (pos>=1 && pos<=n)
  76. Deletion_specific_position (list,pos);
  77. else
  78. {
  79. printf("\n Wrong position\n\n");
  80. goto L;
  81. }
  82. break;
  83. }
  84. else printf("\n No Data to Delete \n\n");
  85. break;
  86.  
  87. case 5: printf("\n choice=Counting Total node\n");
  88. n=count(list);
  89. printf("\n Total Node=%d\n",n);
  90. break;
  91.  
  92. case 6: printf ("\n choice= Linear Search\n");
  93. n= count(list);
  94. if(n!=0)
  95. {
  96. printf("\n Enter value for Searching\n");
  97. scanf("%d", & v);
  98. Linear_search(list,v);
  99. }
  100. else
  101. printf("\n is No Data For Searching\n\n");
  102. break;
  103. }
  104. }
  105.  
  106. }
  107. void Insertion_last_position(struct node *head, int value)
  108. {
  109. struct node *temp;
  110. while(head->p!=NULL)
  111. head = head->p;
  112. temp=(struct node *)malloc(1*sizeof(struct node));
  113. temp->a=value;
  114. temp->p=NULL;
  115. head->p=temp;
  116.  
  117. }
  118. void Display(struct node *head)
  119. {
  120. while(head->p!=NULL)
  121. {
  122. printf("\n%d \t",head->p->a);
  123. head=head->p;
  124. }
  125. }
  126.  
  127. int count(struct node *head)
  128. {
  129. int t=0;
  130. while(head->p!=NULL)
  131. {
  132. t=t+1;
  133. head=head->p;
  134. }
  135. return t;
  136. }
  137. void Insertion_specific_position(struct node*head,int vv, int pp)
  138. {
  139. struct node*temp;
  140. int i=0;
  141. while(head->p!=NULL)
  142. {
  143. if(i==pp-1)
  144. break;
  145. head=head->p;
  146. i=i+1;
  147. }
  148. temp=(struct node*)malloc(1*sizeof(struct node));
  149. temp ->a=vv;
  150. temp ->p=head ->p;
  151. head ->p=temp;
  152. }
  153. void Deletion_specific_position(struct node*head, int pp)
  154. {
  155. struct node*temp;
  156. int i=0;
  157. while(head->p!=NULL)
  158. {
  159. if(i==pp-1)
  160. break;
  161. head=head->p;
  162. i=i+1;
  163. }
  164. temp=head ->p;
  165. head ->p=temp ->p;
  166. free (temp);
  167. }
  168. void Linear_search(struct node*head,int vv)
  169. {
  170. int c=0, i=0;
  171. while(head ->p!=NULL)
  172. {
  173. if (head ->p->a==vv)
  174. {
  175. printf("\n Found At Position =%d",i+1);
  176. c=1;
  177. }
  178. i=i+1;
  179. head= head ->p;
  180. }
  181. if (c ==0)
  182. printf("\n\n Not Found \n\n");
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement