Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #define maks 5
- using namespace std;
- struct antrian{
- int top=-1;
- int bottom=-1;
- char data[maks];
- }ant;
- bool isempty(){
- if (ant.bottom == -1)
- {
- return true;
- }else{
- return false;
- }
- }
- bool isfull(){
- if(ant.top + 1 == maks)
- {
- return true;
- }else{
- return false;
- }
- }
- void enqueue(char data){
- if(isfull()){
- cout << "Antrian Penuh.. " << endl;
- system("pause");
- }else{
- if (ant.bottom == -1) {
- ant.bottom = ant.bottom + 1;
- }
- ant.top = ant.top + 1;
- ant.data[ant.top] = data;
- }
- }
- void dequeue(){
- char data;
- if(isempty()){
- cout << "Antrian kosong" << endl;
- system("pause");
- }else{
- data = ant.data[ant.top];
- cout << "Data " << data << " telah di hapus" << endl;
- if(ant.bottom == ant.top){
- ant.data[ant.bottom] = '\0';
- ant.bottom = ant.bottom - 1;
- }else{
- for (int i = 0; i < ant.top; ++i) {
- ant.data[i] = ant.data[i + 1];
- }
- ant.data[ant.top] = '\0';
- }
- ant.top = ant.top-1;
- }
- }
- void display(){
- for (int i = 0; i <maks; i++) {
- cout << "[" << ant.data[i] << "] ";
- }
- }
- int main(){
- char data;
- int menu;
- do{
- system("cls");
- cout << "Top : " << ant.top << endl;
- cout << "Buttom : " << ant.bottom << endl;
- cout << "Isempty ? "<< isempty() <<endl;
- cout << "Isfull ? " << isfull() <<endl;
- cout << "maks ? " << maks <<endl;
- display();
- cout << endl;
- cout << "Menu: "<<endl;
- cout << "1. Tambah(push)"<<endl;
- cout << "2. Hapus(POP)"<<endl;
- cout << "3. Keluar"<<endl;
- cout << "Masukkan menu: ";
- cin >> menu;
- if(menu == 1){
- cout << "Masukkan data : ";
- cin >>data;
- enqueue(data);
- }else{
- dequeue();
- }
- }while(menu != 3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement