Skip to content

Instantly share code, notes, and snippets.

@aldhinya
Last active May 8, 2018 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aldhinya/f317b4c6954fa00139eecf815d10f204 to your computer and use it in GitHub Desktop.
Save aldhinya/f317b4c6954fa00139eecf815d10f204 to your computer and use it in GitHub Desktop.
Stack Bu Tutuk
#include <iostream>
#include <windows.h>
#include <conio.h>
using namespace std;
int main()
{
int stack_arr[100];
int top=-1;
int bott=-1;
int MAX=4;
int x;
int menu;
char jawab,hapus,lagi;
do
{
cout << "1. Tambah" <<endl;
cout << "2. Hapus" <<endl;
cout << "3. Lihat" <<endl;
cout << "> Pilih Menu = ";
cin >> menu;
if (menu==1)
{
do
{
cout << "\n> Masukkan Nilai X = ";
cin >> x;
if (top==MAX)
{
cout << "> Stack Penuh !" << endl;
}
else if (top==-1)
{
top=top+1;
bott=bott+1;
stack_arr[top]=x;
}
else
{
top=top+1;
stack_arr[top]=x;
}
cout << "> Tambah Lagi ? (y/t) ";
cin >> jawab;
}
while(jawab=='y' || jawab=='Y');
}
else if (menu==2)
{
do
{
if (top==-1)
{
cout << "\n> Stack Sudah Kosong" <<endl;
}
else if (top==bott)
{
top=top-1;
bott=bott-1;
stack_arr[top]=x;
}
else
{
top=top-1;
stack_arr[top]=x;
}
cout << "> Hapus Lagi ? (y/t) ";
cin >> jawab;
}
while(jawab=='y' || jawab=='Y');
}
else if (menu==3)
{
cout <<"\n> Isi Data = " <<endl;
for (top=top; top>=0; top--)
{
cout << " -> " << stack_arr[top] << endl;
}
cout << "\nTekan Enter untuk Kembali ke Menu.";
getch();
}
system("cls");
}
while(true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment