STRUKTUR DATA
Contoh Program Stack
#include <conio.h>
#include <stdio.h>
void main()
{
int stack[10];
int top=-1;
int pilih, i;
do
{
gotoxy(25,2);cout<<"========MENU PILIHAN========"<<endl<<endl;
gotoxy(25,4);cout<<"============================"<<endl;
gotoxy(30,6);cout<<" 1. PUSH "<<endl;
gotoxy(30,7);cout<<" 2. POP "<<endl;
gotoxy(30,8);cout<<" 3. VIEW "<<endl;
gotoxy(30,9);cout<<" 4. EXIT "<<endl;
gotoxy(25,11);cout<<"============================"<<endl;
gotoxy(25,12);printf("Pilih = "); scanf("%d", &pilih);
switch(pilih)
{
case 1://push
clrscr();
if (top > 10)
printf("Stack penuh!\n");
else
{ printf("Data = "); scanf("%d", &stack[top+1]);
top++;
}
break;
case 2://pop
clrscr();
if (top < 0)
printf("Stack kosong!\n");
else
{
printf("Data keluar = %d\n", stack[top]);
top--;
}
break;
case 3://view
cout<<"\n\ndata yang ada pada STACK : \n";
{
for(i=top; i>=0; i--)
printf("%d ", stack[i]);
printf("\n");
}
break;
case 4:
printf("Exit…\n");
break;
}
}while (pilih!=4);
}
Berikan kritik dan saran anda pada pos komentar atau chat box yang telah disediakan..
Semoga blog ini bermanfaat untuk pembaca..
Terima kasih
Youtube : https://www.youtube.com/pyshelaja
instagram : https://www.instagram.com/pysheltv/
Facebook : https://www.facebook.com/PyShel-TV-384015322343195/
IG Produk : https://www.instagram.com/pyshelaja/
FB Produk : https://www.facebook.com/pyshelaja
Website : http://pyshelaja.epizy.com/
Tidak ada komentar:
Posting Komentar