You are on page 1of 4

Tugas Kelompok Materi Stack

No NIM NAMA
1 22103041017 Ahmad Nur Azis
2
3

A. Source Code

#include <iostream>
using namespace std;

#define max 4
string data[max];
int top = 0;

bool isEmpty(){
if (top == 0){
return true;
} else{
return false;
}
}

bool isFull(){
if(top >= max){
return true;
} else {
return false;
}
}

void display(){
if (!isEmpty()){
cout<< "Data Tersimpan : "<<endl;
for(int a =0; a< top; a++){
cout<< a+1 << ". " << data[a] << endl;
}
} else {
cout << "Data Tidak Tersedia !" << endl;
}
if(isFull()){
cout << "Stack Penuh" << endl;
}
cout << endl;
}
void push (){
if (!isFull()){
cout <<"Masukkan Data : ";
cin >> data[top];
top++;
}
}

void pop(){
if(!isEmpty()){
top--;;
}
}

int main(){
int pil;
string isi;

stack :
system("cls");
display();
cout << "Menu Utama\n1. push\n2.pop\nPilih : ";
cin >> pil;

if(pil==1){
system("cls");
push();
goto stack;
} else if (pil == 2){
pop();
goto stack;
}
cout<< " Program Selesai";

}
B. Hasil ketika script program dijalankan
-- Terima Kasih --

You might also like