Guest User

Untitled

a guest
Jan 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <windows.h>
  5. #include <malloc.h>
  6.  
  7. using namespace std;
  8.  
  9. int pilih;
  10. int menu_Ari_S;
  11. int pilih_Ari_S();
  12. int add_baru_Ari_S();
  13. int add_dpn_Ari_S();
  14. int add_blk_Ari_S();
  15. int del_dpn_Ari_S();
  16. int del_blk_Ari_S();
  17. int tampil_Ari_S();
  18. struct simpul
  19. {
  20. char data_Ari_S[15];
  21. struct simpul *next;
  22. }*baru, *awal=NULL, *akhir=NULL,*hapus,*bantu;
  23.  
  24. main()
  25. {
  26. do
  27. {
  28. system("cls");
  29. cout<<"================================================"<<endl;
  30. cout<<"Tugas 3 : Aplikasi Single Linked List (Individu)"<<endl;
  31. cout<<"================================================"<<endl;
  32. cout<<"MENU UTAMA :"<<endl;
  33. cout<<" 1. Menambah node di depan"<<endl;
  34. cout<<" 2. Menambah node di belakang"<<endl;
  35. cout<<" 3. Menghapus node di depan"<<endl;
  36. cout<<" 4. Menghapus node di belakang"<<endl;
  37. cout<<" 5. Menampilkan isi linked list"<<endl;
  38. cout<<" 6. Exit"<<endl;
  39. cout<<"------------------------------------------------"<<endl;
  40. cout<<"Inputkan Pilihan Anda : ";
  41. cin>>menu_Ari_S;
  42. pilih_Ari_S();
  43. } while(menu_Ari_S!=6);
  44. return 0;
  45. }
  46.  
  47. int pilih_Ari_S()
  48. {
  49. if(menu_Ari_S==1)
  50. add_dpn_Ari_S();
  51. else if(menu_Ari_S==2)
  52. add_blk_Ari_S();
  53. else if(menu_Ari_S==3)
  54. del_dpn_Ari_S();
  55. else if(menu_Ari_S==4)
  56. del_blk_Ari_S();
  57. else if(menu_Ari_S==5)
  58. tampil_Ari_S();
  59. else
  60. {
  61. system("cls");
  62. cout<<"\n Terimakasih \n";
  63. getch();
  64. }
  65. }
  66.  
  67. int add_baru_Ari_S()
  68. {
  69. system("cls");
  70. baru=(simpul*) malloc(sizeof(struct simpul));
  71. cout<<" Masukkan data : ";cin>>baru->data_Ari_S;
  72. baru->next=NULL;
  73. }
  74.  
  75. int add_dpn_Ari_S()
  76. {
  77. system("cls");
  78. add_baru_Ari_S();
  79. if(awal==NULL)
  80. {
  81. awal=baru;
  82. akhir=baru;
  83. akhir->next=NULL;
  84. }
  85. else
  86. {
  87. baru->next=awal;
  88. awal=baru;
  89. }
  90. }
  91.  
  92. int add_blk_Ari_S()
  93. {
  94. add_baru_Ari_S();
  95. if(awal==NULL)
  96. {
  97. awal=baru;
  98. }
  99. else
  100. {
  101. akhir->next=baru;
  102. }
  103. akhir=baru;
  104. akhir->next=NULL;
  105. }
  106.  
  107. int del_dpn_Ari_S()
  108. {
  109. if (awal==NULL)
  110. {
  111. cout<<"\n Tidak ada data dalam linked list !!"<<endl;
  112. getch();
  113. system("cls");
  114. }
  115.  
  116. else
  117. {
  118. hapus=awal;
  119. awal=awal->next;
  120. free(hapus);
  121. }
  122. }
  123.  
  124. int del_blk_Ari_S()
  125. {
  126. if (awal==NULL)
  127. {
  128. cout<<"\n Tidak ada data dalam linked list !!"<<endl;
  129. getch();
  130. system("cls");
  131. }
  132. else if(awal==akhir)
  133. {
  134. hapus=awal;
  135. awal=awal->next;
  136. free(hapus);
  137. }
  138. else
  139. {
  140. hapus=awal;
  141. while(hapus->next!=akhir)
  142. hapus=hapus->next;
  143. akhir=hapus;
  144. hapus=akhir->next;
  145. akhir->next=NULL;
  146. free(hapus);
  147. }
  148. }
  149.  
  150. int tampil_Ari_S()
  151. {
  152. if (awal==NULL)
  153. {
  154. cout<<"\n Tidak ada data dalam linked list !! "<<endl;
  155. }
  156.  
  157. else
  158. {
  159. system("cls");
  160. cout<<"Menampilkan semua isi di dalam linked list : \n\n";
  161. bantu=awal;
  162. while(bantu!=NULL)
  163. {
  164. cout<<bantu->data_Ari_S<<" -> ";
  165. bantu=bantu->next;
  166. }
  167. cout<<"NULL";
  168. }
  169. getch();
  170. }
Add Comment
Please, Sign In to add comment