Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.74 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<conio.h>
  4. struct node
  5. {
  6. int data;
  7. struct node *link;
  8. };
  9. struct node *start =NULL;
  10.  
  11. void enq_first()
  12. {
  13.  
  14. struct node *temp;
  15. temp=(struct node*)malloc(sizeof(struct node));
  16. printf("\nEnter value to insert : ");scanf("%d",&temp->data);
  17. //temp->data=x;
  18. printf("Inserted value is : %d",temp->data);
  19. if(start==NULL)
  20. {temp->link=NULL;
  21. start=temp;}
  22. else
  23. {
  24. temp->link=start;
  25. start=temp;
  26. }
  27.  
  28. }
  29.  
  30. /*void enq_int(int x)
  31. {
  32. int i,pos;
  33. struct node *temp;
  34. struct node *temp1;
  35. temp=(struct node*)malloc(sizeof(struct node));
  36. temp1=(struct node*)malloc(sizeof(struct node));
  37.  
  38. temp->data=x;
  39. printf("Enter the position to enter the data : ");scanf("%d",&pos);
  40. temp1=start;
  41. for(i=1;i<pos;i++)
  42. {
  43. temp1=temp1->link;
  44. }
  45. temp->link=temp1->link;
  46. temp1->link=temp;
  47. return;
  48. }
  49. */
  50. /*void enq_end(int x)
  51. {
  52. struct node *temp;
  53. struct node *temp1;
  54. temp=(struct node*)malloc(sizeof(struct node));
  55. temp1=(struct node*)malloc(sizeof(struct node));
  56. temp->data=x;
  57. temp->link=NULL;
  58.  
  59. if(start==NULL){start=temp;return;}
  60.  
  61. temp1=start;
  62. while(temp1->link!=NULL){temp1=temp1->link;}
  63. temp1->link=temp;
  64. return;
  65. }
  66. */
  67. void disp()
  68. {
  69. struct node *temp1;
  70. temp1=(struct node*)malloc(sizeof(struct node));
  71. if(start==NULL){printf("\nList is Empty!!");}
  72. else
  73. {
  74. temp1=start;
  75. printf("The elements in the list : ");
  76. while(temp1->link!=NULL)
  77. {
  78. printf(" %d, ",temp1->data);
  79. temp1=temp1->link;
  80. }
  81. }
  82. }
  83. int main()
  84. {
  85. int pos;
  86. int choice,value;
  87. int count=0;
  88. while(1)
  89. {
  90. printf("\n\n\nOPTIONS MENU");
  91. printf("\n1.Insert at Beginning \n2.Insert at Specified Position");
  92. printf("\n3.Insert at End\n4.Display\n5.EXIT");
  93. printf("\nSelect your decision : ");
  94. scanf("%d",&choice);
  95.  
  96. switch(choice)
  97. {
  98. case 1:
  99. enq_first();break;
  100. /*case 2:
  101. printf("\nEnter value to insert : ");scanf("%d",&value);
  102. enq_int(value);break;
  103. case 3:
  104. printf("\nEnter value to insert : ");scanf("%d",&value);
  105. enq_end(value);break;*/
  106. case 4:
  107. disp();break;
  108. case 5: exit(0);
  109. default:
  110. printf("Wrong Selection!");
  111. }
  112. }
  113. getch();
  114. return 0;
  115. }
  116. #include<stdio.h>
  117. #include<stdlib.h>
  118. #include<conio.h>
  119. struct node
  120. {
  121. int data;
  122. struct node *link;
  123. };
  124. struct node *start =NULL;
  125.  
  126. void enq_first()
  127. {
  128.  
  129. struct node *temp;
  130. temp=(struct node*)malloc(sizeof(struct node));
  131. printf("\nEnter value to insert : ");scanf("%d",&temp->data);
  132. //temp->data=x;
  133. printf("Inserted value is : %d",temp->data);
  134. if(start==NULL)
  135. {temp->link=NULL;
  136. start=temp;}
  137. else
  138. {
  139. temp->link=start;
  140. start=temp;
  141. }
  142.  
  143. }
  144.  
  145. /*void enq_int(int x)
  146. {
  147. int i,pos;
  148. struct node *temp;
  149. struct node *temp1;
  150. temp=(struct node*)malloc(sizeof(struct node));
  151. temp1=(struct node*)malloc(sizeof(struct node));
  152.  
  153. temp->data=x;
  154. printf("Enter the position to enter the data : ");scanf("%d",&pos);
  155. temp1=start;
  156. for(i=1;i<pos;i++)
  157. {
  158. temp1=temp1->link;
  159. }
  160. temp->link=temp1->link;
  161. temp1->link=temp;
  162. return;
  163. }
  164. */
  165. /*void enq_end(int x)
  166. {
  167. struct node *temp;
  168. struct node *temp1;
  169. temp=(struct node*)malloc(sizeof(struct node));
  170. temp1=(struct node*)malloc(sizeof(struct node));
  171. temp->data=x;
  172. temp->link=NULL;
  173.  
  174. if(start==NULL){start=temp;return;}
  175.  
  176. temp1=start;
  177. while(temp1->link!=NULL){temp1=temp1->link;}
  178. temp1->link=temp;
  179. return;
  180. }
  181. */
  182. void disp()
  183. {
  184. struct node *temp1;
  185. temp1=(struct node*)malloc(sizeof(struct node));
  186. if(start==NULL){printf("\nList is Empty!!");}
  187. else
  188. {
  189. temp1=start;
  190. printf("The elements in the list : ");
  191. while(temp1->link!=NULL)
  192. {
  193. printf(" %d, ",temp1->data);
  194. temp1=temp1->link;
  195. }
  196. }
  197. }
  198. int main()
  199. {
  200. int pos;
  201. int choice,value;
  202. int count=0;
  203. while(1)
  204. {
  205. printf("\n\n\nOPTIONS MENU");
  206. printf("\n1.Insert at Beginning \n2.Insert at Specified Position");
  207. printf("\n3.Insert at End\n4.Display\n5.EXIT");
  208. printf("\nSelect your decision : ");
  209. scanf("%d",&choice);
  210.  
  211. switch(choice)
  212. {
  213. case 1:
  214. enq_first();break;
  215. /*case 2:
  216. printf("\nEnter value to insert : ");scanf("%d",&value);
  217. enq_int(value);break;
  218. case 3:
  219. printf("\nEnter value to insert : ");scanf("%d",&value);
  220. enq_end(value);break;*/
  221. case 4:
  222. disp();break;
  223. case 5: exit(0);
  224. default:
  225. printf("Wrong Selection!");
  226. }
  227. }
  228. getch();
  229. return 0;
  230. }
  231. #include<stdio.h>
  232. #include<stdlib.h>
  233. #include<conio.h>
  234. struct node
  235. {
  236. int data;
  237. struct node *link;
  238. };
  239. struct node *start =NULL;
  240.  
  241. void enq_first()
  242. {
  243.  
  244. struct node *temp;
  245. temp=(struct node*)malloc(sizeof(struct node));
  246. printf("\nEnter value to insert : ");scanf("%d",&temp->data);
  247. //temp->data=x;
  248. printf("Inserted value is : %d",temp->data);
  249. if(start==NULL)
  250. {temp->link=NULL;
  251. start=temp;}
  252. else
  253. {
  254. temp->link=start;
  255. start=temp;
  256. }
  257.  
  258. }
  259.  
  260. /*void enq_int(int x)
  261. {
  262. int i,pos;
  263. struct node *temp;
  264. struct node *temp1;
  265. temp=(struct node*)malloc(sizeof(struct node));
  266. temp1=(struct node*)malloc(sizeof(struct node));
  267.  
  268. temp->data=x;
  269. printf("Enter the position to enter the data : ");scanf("%d",&pos);
  270. temp1=start;
  271. for(i=1;i<pos;i++)
  272. {
  273. temp1=temp1->link;
  274. }
  275. temp->link=temp1->link;
  276. temp1->link=temp;
  277. return;
  278. }
  279. */
  280. /*void enq_end(int x)
  281. {
  282. struct node *temp;
  283. struct node *temp1;
  284. temp=(struct node*)malloc(sizeof(struct node));
  285. temp1=(struct node*)malloc(sizeof(struct node));
  286. temp->data=x;
  287. temp->link=NULL;
  288.  
  289. if(start==NULL){start=temp;return;}
  290.  
  291. temp1=start;
  292. while(temp1->link!=NULL){temp1=temp1->link;}
  293. temp1->link=temp;
  294. return;
  295. }
  296. */
  297. void disp()
  298. {
  299. struct node *temp1;
  300. temp1=(struct node*)malloc(sizeof(struct node));
  301. if(start==NULL){printf("\nList is Empty!!");}
  302. else
  303. {
  304. temp1=start;
  305. printf("The elements in the list : ");
  306. while(temp1->link!=NULL)
  307. {
  308. printf(" %d, ",temp1->data);
  309. temp1=temp1->link;
  310. }
  311. }
  312. }
  313. int main()
  314. {
  315. int pos;
  316. int choice,value;
  317. int count=0;
  318. while(1)
  319. {
  320. printf("\n\n\nOPTIONS MENU");
  321. printf("\n1.Insert at Beginning \n2.Insert at Specified Position");
  322. printf("\n3.Insert at End\n4.Display\n5.EXIT");
  323. printf("\nSelect your decision : ");
  324. scanf("%d",&choice);
  325.  
  326. switch(choice)
  327. {
  328. case 1:
  329. enq_first();break;
  330. /*case 2:
  331. printf("\nEnter value to insert : ");scanf("%d",&value);
  332. enq_int(value);break;
  333. case 3:
  334. printf("\nEnter value to insert : ");scanf("%d",&value);
  335. enq_end(value);break;*/
  336. case 4:
  337. disp();break;
  338. case 5: exit(0);
  339. default:
  340. printf("Wrong Selection!");
  341. }
  342. }
  343. getch();
  344. return 0;
  345. }
  346. #include<stdio.h>
  347. #include<stdlib.h>
  348. #include<conio.h>
  349. struct node
  350. {
  351. int data;
  352. struct node *link;
  353. };
  354. struct node *start =NULL;
  355.  
  356. void enq_first()
  357. {
  358.  
  359. struct node *temp;
  360. temp=(struct node*)malloc(sizeof(struct node));
  361. printf("\nEnter value to insert : ");scanf("%d",&temp->data);
  362. //temp->data=x;
  363. printf("Inserted value is : %d",temp->data);
  364. if(start==NULL)
  365. {temp->link=NULL;
  366. start=temp;}
  367. else
  368. {
  369. temp->link=start;
  370. start=temp;
  371. }
  372.  
  373. }
  374.  
  375. /*void enq_int(int x)
  376. {
  377. int i,pos;
  378. struct node *temp;
  379. struct node *temp1;
  380. temp=(struct node*)malloc(sizeof(struct node));
  381. temp1=(struct node*)malloc(sizeof(struct node));
  382.  
  383. temp->data=x;
  384. printf("Enter the position to enter the data : ");scanf("%d",&pos);
  385. temp1=start;
  386. for(i=1;i<pos;i++)
  387. {
  388. temp1=temp1->link;
  389. }
  390. temp->link=temp1->link;
  391. temp1->link=temp;
  392. return;
  393. }
  394. */
  395. /*void enq_end(int x)
  396. {
  397. struct node *temp;
  398. struct node *temp1;
  399. temp=(struct node*)malloc(sizeof(struct node));
  400. temp1=(struct node*)malloc(sizeof(struct node));
  401. temp->data=x;
  402. temp->link=NULL;
  403.  
  404. if(start==NULL){start=temp;return;}
  405.  
  406. temp1=start;
  407. while(temp1->link!=NULL){temp1=temp1->link;}
  408. temp1->link=temp;
  409. return;
  410. }
  411. */
  412. void disp()
  413. {
  414. struct node *temp1;
  415. temp1=(struct node*)malloc(sizeof(struct node));
  416. if(start==NULL){printf("\nList is Empty!!");}
  417. else
  418. {
  419. temp1=start;
  420. printf("The elements in the list : ");
  421. while(temp1->link!=NULL)
  422. {
  423. printf(" %d, ",temp1->data);
  424. temp1=temp1->link;
  425. }
  426. }
  427. }
  428. int main()
  429. {
  430. int pos;
  431. int choice,value;
  432. int count=0;
  433. while(1)
  434. {
  435. printf("\n\n\nOPTIONS MENU");
  436. printf("\n1.Insert at Beginning \n2.Insert at Specified Position");
  437. printf("\n3.Insert at End\n4.Display\n5.EXIT");
  438. printf("\nSelect your decision : ");
  439. scanf("%d",&choice);
  440.  
  441. switch(choice)
  442. {
  443. case 1:
  444. enq_first();break;
  445. /*case 2:
  446. printf("\nEnter value to insert : ");scanf("%d",&value);
  447. enq_int(value);break;
  448. case 3:
  449. printf("\nEnter value to insert : ");scanf("%d",&value);
  450. enq_end(value);break;*/
  451. case 4:
  452. disp();break;
  453. case 5: exit(0);
  454. default:
  455. printf("Wrong Selection!");
  456. }
  457. }
  458. getch();
  459. return 0;
  460. }
  461. #include<stdio.h>
  462. #include<stdlib.h>
  463. #include<conio.h>
  464. struct node
  465. {
  466. int data;
  467. struct node *link;
  468. };
  469. struct node *start =NULL;
  470.  
  471. void enq_first()
  472. {
  473.  
  474. struct node *temp;
  475. temp=(struct node*)malloc(sizeof(struct node));
  476. printf("\nEnter value to insert : ");scanf("%d",&temp->data);
  477. //temp->data=x;
  478. printf("Inserted value is : %d",temp->data);
  479. if(start==NULL)
  480. {temp->link=NULL;
  481. start=temp;}
  482. else
  483. {
  484. temp->link=start;
  485. start=temp;
  486. }
  487.  
  488. }
  489.  
  490. /*void enq_int(int x)
  491. {
  492. int i,pos;
  493. struct node *temp;
  494. struct node *temp1;
  495. temp=(struct node*)malloc(sizeof(struct node));
  496. temp1=(struct node*)malloc(sizeof(struct node));
  497.  
  498. temp->data=x;
  499. printf("Enter the position to enter the data : ");scanf("%d",&pos);
  500. temp1=start;
  501. for(i=1;i<pos;i++)
  502. {
  503. temp1=temp1->link;
  504. }
  505. temp->link=temp1->link;
  506. temp1->link=temp;
  507. return;
  508. }
  509. */
  510. /*void enq_end(int x)
  511. {
  512. struct node *temp;
  513. struct node *temp1;
  514. temp=(struct node*)malloc(sizeof(struct node));
  515. temp1=(struct node*)malloc(sizeof(struct node));
  516. temp->data=x;
  517. temp->link=NULL;
  518.  
  519. if(start==NULL){start=temp;return;}
  520.  
  521. temp1=start;
  522. while(temp1->link!=NULL){temp1=temp1->link;}
  523. temp1->link=temp;
  524. return;
  525. }
  526. */
  527. void disp()
  528. {
  529. struct node *temp1;
  530. temp1=(struct node*)malloc(sizeof(struct node));
  531. if(start==NULL){printf("\nList is Empty!!");}
  532. else
  533. {
  534. temp1=start;
  535. printf("The elements in the list : ");
  536. while(temp1->link!=NULL)
  537. {
  538. printf(" %d, ",temp1->data);
  539. temp1=temp1->link;
  540. }
  541. }
  542. }
  543. int main()
  544. {
  545. int pos;
  546. int choice,value;
  547. int count=0;
  548. while(1)
  549. {
  550. printf("\n\n\nOPTIONS MENU");
  551. printf("\n1.Insert at Beginning \n2.Insert at Specified Position");
  552. printf("\n3.Insert at End\n4.Display\n5.EXIT");
  553. printf("\nSelect your decision : ");
  554. scanf("%d",&choice);
  555.  
  556. switch(choice)
  557. {
  558. case 1:
  559. enq_first();break;
  560. /*case 2:
  561. printf("\nEnter value to insert : ");scanf("%d",&value);
  562. enq_int(value);break;
  563. case 3:
  564. printf("\nEnter value to insert : ");scanf("%d",&value);
  565. enq_end(value);break;*/
  566. case 4:
  567. disp();break;
  568. case 5: exit(0);
  569. default:
  570. printf("Wrong Selection!");
  571. }
  572. }
  573. getch();
  574. return 0;
  575. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement