Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- int front=-1;
- int rear=-1;
- int Max=5;
- struct data
- {
- int numb;
- };
- bool isFull()
- {
- if (rear==Max-1)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- bool isEmpty()
- {
- if (rear==-1)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- int main()
- {
- data Data[5];
- int pil;
- do
- {
- system("cls");
- cout << "Pilihan !!!" << endl;
- cout << "1. Enqueue" << endl;
- cout << "2. Dequeue" << endl;
- cout << "3. Show" << endl;
- cout << "4. Exit" << endl;
- cout << "Masukkan pilihan = ";
- cin >> pil;
- switch (pil)
- {
- case 1:
- {
- if (isFull()==true)
- {
- cerr << "Data penuh" << endl;
- }
- else
- {
- if (front==-1)
- {
- front++;
- }
- rear++;
- cout << "Masukkan angka = ";
- cin >> Data[rear].numb;
- }
- system("pause");
- break;
- }
- case 2:
- {
- if (isEmpty()==true)
- {
- cerr << "Data masih kosong" << endl;
- }
- else if (front==rear)
- {
- Data[front].numb='\0';
- front--;
- rear--;
- cout << "Data telah di hapus" << endl;
- }
- else
- {
- for(int i=0;i<rear;++i)
- {
- Data[i]=Data[i+1];
- }
- Data[rear].numb='\0';
- rear--;
- cout << "Data telah di hapus" <<endl;
- }
- system("pause");
- break;
- }
- case 3:
- {
- if(isEmpty()==true)
- {
- cout << "Data masih kosong!!!" << endl;
- }
- else
- {
- for (int i=0;i<=rear;i++)
- {
- cout << "<- [ " << Data[i].numb << " ] ";
- }
- cout << endl;
- }
- system("pause");
- break;
- }
- case 4:
- {
- return 0;
- }
- default:
- {
- cerr << "Pilihan tidak ada" << endl;
- system("pause");
- break;
- }
- }
- }while(pil<=4);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement