Advertisement
gregoriusjimmy

Untitled

Nov 13th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void create() {
  6.    
  7. }
  8.  
  9. void cetak(char queue[], char namaArray, int n, int front, char isiFront, int rear, char isiRear, int noel) {
  10.     cout << namaArray << " = ";
  11.    
  12.     for (int i = 0; i < n; i++) {
  13.         cout << "[" << queue[i] << "]";
  14.     }
  15.    
  16.     cout << "\nFront: " << isiFront;
  17.     if (isiFront == NULL) {
  18.         cout << front;
  19.     } else {
  20.         cout << ", " << front;
  21.     }
  22.    
  23.     cout << "\nRear: " << isiRear;
  24.     if (isiRear == NULL) {
  25.         cout << rear;  
  26.     } else {
  27.         cout << ", " << rear;
  28.     }
  29.    
  30.     cout << "\nNoel: " << noel;
  31. }
  32.  
  33. int main() {
  34.    
  35.    
  36.     cout << "====Program Queue====" << endl;
  37.     cout << "Masukan nama array: ";
  38.     char namaArray;
  39.     cin >> namaArray;
  40.     cout << "Jumlah " << namaArray << " = ";
  41.     int n, front, rear;
  42.     cin >> n;
  43.     char queue[n], isiFront, isiRear;
  44.    
  45.     for (int i = 0; i < n; i++) {
  46.         cout << "Masukan elemen ke-" << i+1 << " = ";
  47.         cin >> queue[i];
  48.         cout << endl;
  49.         if (i == 0) {
  50.             front = i+1;
  51.             isiFront = queue[i];
  52.         } else if (i == n-1) {
  53.             rear = i+1;
  54.             isiRear = queue[i];
  55.         }
  56.     }
  57.     int noel = n;
  58.    
  59.     cetak(queue, namaArray, n, front, isiFront, rear, isiRear, noel);
  60.    
  61.    
  62.    
  63.     cout << "\n====Operasi Queue====";
  64.     cout << "\n1. Create";
  65.     cout << "\n2. IsEmpety";
  66.     cout << "\n3. Insert";
  67.     cout << "\n4. Remove";
  68.    
  69.     int pilih;
  70.     cout << "\nPilih : ";
  71.     cin >> pilih;
  72.    
  73.     char isEmpty[5];
  74.    
  75.     if (pilih == 1) {
  76.         for (int i = 0; i < n; i++) {
  77.             queue[i] = NULL;
  78.             front = 0;
  79.             isiFront = NULL;
  80.             rear = 0;
  81.             isiRear = NULL;
  82.             noel = 0;
  83.         }
  84.         cetak(queue, namaArray, n, front, isiFront, rear, isiRear, noel);
  85.     } else if (pilih == 2) {
  86.         if (noel == 0) {
  87.             isEmpty[] = "false";
  88.         } else if (noel != 0) {
  89.             isEmpty[] = "true";
  90.         }
  91.         cout << "isEmpty = " << isEmpty;
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement