Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <iomanip.h>
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #define max 10
  6.  
  7. typedef struct
  8. {
  9. int head;
  10. int tail;
  11.  
  12. char *t[max];
  13. int a[max], s[max];
  14.  
  15. } queue;
  16.  
  17. queue pos;
  18.  
  19. void creat()
  20. {
  21. pos.head=pos.tail=-1;
  22. }
  23.  
  24. iempty()
  25. {
  26. if(pos.tail==-1)
  27. return 1;
  28. else
  29. return 0;
  30. }
  31.  
  32. ifull()
  33. {
  34. if(pos.tail==max-1)
  35. return 1;
  36. else
  37. return 0;
  38. }
  39.  
  40. void enqueue(char *q, int w, int e)
  41. {
  42. if(iempty()==1)
  43. {
  44. pos.head=pos.tail=0;
  45. pos.t[pos.tail]=q;
  46. pos.a[pos.tail]=w;
  47. pos.s[pos.tail]=e;
  48. }
  49.  
  50. else if(ifull()==0)
  51. {
  52. pos.tail++;
  53. pos.t[pos.tail]=q;
  54. pos.a[pos.tail]=w;
  55. pos.s[pos.tail]=e;
  56. }
  57.  
  58. else if(ifull()==1)
  59. {
  60. cout<<"QUEUE PENUH";
  61. }
  62. }
  63.  
  64. dequeue()
  65. {
  66. if(iempty()==0)
  67. {
  68. int i;
  69. char *z=pos.t[pos.tail];
  70. int x=pos.a[pos.tail];
  71. int c=pos.s[pos.tail];
  72.  
  73. for(i=pos.head; 1<=pos.tail-1; i++)
  74. {
  75. pos.t[i]=pos.t[i+1];
  76. pos.a[i]=pos.a[i+1];
  77. pos.s[i]=pos.s[i+1];
  78. }
  79.  
  80. pos.tail--;
  81. cout<<"DATA YANG DIHAPUS ADALAH : \n";
  82. cout<<"Nama Barang : "<<z<<endl;
  83. cout<<"Kode Barang : "<<x<<endl;
  84. cout<<"Harga Barang : "<<c<<endl;
  85. }
  86.  
  87. else if(iempty()==1)
  88. { cout<<"DATA EROR......QUEUE KOSONG"; }
  89.  
  90. return 1;
  91. }
  92.  
  93. void clear()
  94. {
  95. pos.head=pos.tail=-1;
  96. cout<<"QUEUE CLEAR";
  97. }
  98.  
  99. void view()
  100. {
  101. if(iempty()==0)
  102. {
  103. cout<<"NO Nama Barang Kode Barang Harga Barang\n";
  104.  
  105. for(int i=pos.head; i<=pos.tail; i++)
  106. {
  107. cout<<setiosflags(ios::left)<<setw(3)<<i;
  108. cout<<setiosflags(ios::left)<<setw(15)<<pos.t[i];
  109. cout<<setiosflags(ios::left)<<setw(15)<<pos.a[i];
  110. cout<<setiosflags(ios::left)<<setw(9)<<pos.s[i]<<endl;
  111. }
  112. }
  113. else
  114. { cout<<"NO Nama Barang Kode Barang Harga Barang\n"; }
  115. }
  116.  
  117. main()
  118. {
  119.  
  120. int menu;
  121. int acc, tpd;
  122. char tip[30];
  123.  
  124. creat();
  125.  
  126. do{
  127.  
  128. clrscr();
  129.  
  130. cout<<"===========================\n";
  131. cout<<" MENU PROGRAM QUEUE\n";
  132. cout<<"===========================\n";
  133. cout<<"1.ENQUEUE\n";
  134. cout<<"2.DEQUEUE\n";
  135. cout<<"3.CLEAR\n";
  136. cout<<"4.VIEW\n";
  137. cout<<"5.EXIT\n";
  138. cout<<"===========================\n";
  139. cout<<"PILIH MENU : "; cin>>menu;
  140.  
  141. switch(menu)
  142. {
  143. case 1:
  144. cout<<"MASUKAN Nama Barang : "; gets(tip);
  145. cout<<"MASUKAN Kode Barang : "; cin>>acc;
  146. cout<<"MASUKAN Harga Barang : "; cin>>tpd;
  147.  
  148. enqueue(tip, acc, tpd);
  149. break;
  150.  
  151. case 2:
  152. dequeue();
  153. break;
  154.  
  155. case 3:
  156. clear();
  157. break;
  158.  
  159. case 4:
  160. view();
  161. break;
  162.  
  163. case 5:
  164. cout<<"exitttt.......bye...... :):D";
  165. break;
  166. }
  167. getch();
  168.  
  169. }while(menu!=5);
  170.  
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement