Gambar 1.1 Diagram Detail
Gambar 1.2 Diagram Konteks
Gambar 1.3 Diagram Nol
#include "conio.h"
#include
"iostream.h"
#include "stdio.h"
//function
int max=5;
int data[5];
int atas=-1;
//pengadaian if, else
int isempty()
{
if (atas==-1)
return
1;
else
return
0;
}
int isfull()
{
if(atas==max-1)
return
1;
else
return
0;
}
int push()
{
if (isfull())
{
cout<<"Tumpukan Sudah
Penuh!";
getch();
}
else
{
atas++;
cout<<"Data masukkan :
";cin>>data[atas];
}
}
int pop()
{
if (isempty())
{
cout<<"stack
kosong! ";
getch();
}
else
{
cout<<"Data keluaran :
"<<data[atas];
atas--;
getch();
}
}
int clear()
{
atas=-1;
cout<<"stack
dikosongkan!";
getch();
}
int view()
{
if (isempty())
{
cout<<"stack
kosong!";
getch();
}
else
{
//perulangan for
for(int
a=atas;a>=0;a--)
cout<<"Data
pada tumpukan ke "<<a<<" :
"<<data[a]<<endl;
getch();
}
}
main()
{
char lagi;
int jawab;
menu:
//perulangan do while
do
{
clrscr();
cout<<"\t---------
Program Stack ----------"<<endl;
cout<<endl;
cout<<"Menu
:"<<endl;
cout<<"\t1. Push
"<<endl;
cout<<"\t2. Pop
"<<endl;
cout<<"\t3. Clear
"<<endl;
cout<<"\t4. View
"<<endl;
cout<<"\t5. Exit
"<<endl;
cout<<endl;
cout<<"Masukkan
Pilihan : ";cin>>jawab;
//pengandaian switch case
switch(jawab)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
clear();
break;
case 4:
view();
break;
}
}
//perulangan do while
while (jawab != 5);
cout<<endl;
//perulangan goto
cout<<"Input Data
Kembali [Y||T] : ";cin>>lagi;
if (lagi=='Y'||lagi=='y')
goto menu;
else
cout<<endl;
cout<<"\t\t***Terima
Kasih***"<<endl;
getch();
}
|