Advertisement
Guest User

yaw

a guest
Jun 27th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. struct node{
  7. string data;
  8. int har;
  9. node *next, *prev;
  10. }*head, *tail;
  11.  
  12. void init(){
  13. head = NULL;
  14. }
  15.  
  16. bool isempty() {
  17. if (head == NULL)
  18. return true;
  19. else return false;
  20. }
  21.  
  22. void insertbelakang () {
  23. string x;
  24. int q;
  25.  
  26. cout << "masukkan barang : ";
  27. cin >> x;
  28. cout << "masukkan harga : ";
  29. cin>>q;
  30.  
  31. node *baru;
  32. baru = new node;
  33.  
  34.  
  35. baru -> data = x;
  36. baru -> har = q;
  37. baru -> next = NULL;
  38. baru -> prev = NULL;
  39.  
  40. if (isempty()) {
  41. head = baru;
  42. tail = baru;
  43. tail -> next = NULL;
  44. tail -> prev = NULL;
  45. } else {
  46.  
  47. tail -> next = baru;
  48. baru -> prev = tail;
  49. tail = baru;
  50. tail -> next = NULL;
  51. }
  52. }
  53.  
  54. void cetak() {
  55. node *bantu = head;
  56.  
  57. if (isempty()) {
  58. cout << "List kosong";
  59. } else {
  60. while (bantu != NULL) {
  61. cout << bantu -> data << "\t";
  62. cout << bantu -> har << "\n";
  63. bantu = bantu -> next;
  64.  
  65. }
  66. }
  67. }
  68.  
  69.  
  70.  
  71. int main()
  72. {
  73. init();
  74.  
  75. int pilih, q;
  76. string x;
  77.  
  78. menu :
  79. system("cls");
  80. cout << "*****Menu*****\n";
  81. cout << "1. Input Barang\n";
  82. cout << "2. tampilkan list barang\n";
  83. cout << "3. Keluar\n";
  84.  
  85. cout<< endl;
  86. cout << "pilih : ";
  87. cin >> pilih;
  88.  
  89. switch(pilih){
  90. case 1 :
  91. insertbelakang();
  92. system("pause");
  93. goto menu;
  94. break;
  95. case 2 :
  96. cetak();
  97. cout << endl << endl;
  98. system("pause");
  99. goto menu;
  100. break;
  101. case 3 :
  102. return 0;
  103.  
  104. }
  105. return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement