contoh program stack

# include <iostream.h>

# include <stdlib.h>

# include <conio.h>

# define alamat Elemen*

// untuk menampilkan atau mencetak tumpukan

void tampilTumpukan(Tumpukan T)

{

alamat P = T.atas;

cout << “Isi stack : “;

while ((P!=NULL)) {

cout << P->Info << ” – “;

P = P->Berikut;

}

cout << “\n”;

}

// untuk mencetak menu utama

void cetakMenu(){

cout << “***CONTOH TUMPUKAN***“;

cout << “\n 1. Tambah elemen\n”;

cout << “ 2. Hapus elemen\n”;

cout << “ 3. Cetak tumpukan\n”;

cout << “ 4. Selesai\n\n”;

}

// program utama

int main()

{

Tumpukan T;

int selesai;

int pilMenu;

tInfo elm;

inisialisasi(&T);

selesai = 0;

do

{

clrscr;

cetakMenu();

cout << “Menu yg dipilih : “;

cin >> pilMenu;

switch(pilMenu) {

case 1 : cout << “\nMasukkan elemen yg ditambahkan : “;

cin >> elm;

Push(&T,elm);

break;

case 2 : if (tumpukanKosong(T))

{

cout << “\nTumpukan kosong kosong, tidak bisa dihapus\n”;

}

else

{

Pop(&T, &elm);

cout << “\nElemen yang dihapus : ” << elm << “\n”;

}

break;

case 3 : tampilTumpukan(T);

break;

default : selesai = 1;

}

}

while ( !selesai );

return 1;}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s