Contoh Double Stack
Contoh Double Stack
#include <cstdlib>
#include <iostream>
inisialisasi();
push1();
cetak();
pop1();
cout<<"setelah dihapus"<<endl;
cetak();
system("PAUSE");
return EXIT_SUCCESS;
}
void inisialisasi(void)
{
top1=-1;
top2=n;
}
void push1(void)
{
char x;
while((top2-top1)>1)
{
cout<<top2-top1<<endl;
cout<<"Masukan karakter : ";cin>>x;
S[++top1]=x;
}
cout<<"Pengisian stack1 sudah penuh"<<endl;
}
void push2(void)//mengisi stack sampai penuh menggunakan top2
{
char x;
while((top2-top1)>1)
{
cout<<top2-top1<<endl;
cout<<"Masukan karakter : ";cin>>x;
S[--top2]=x;
}
cout<<"Pengisian stack1 sudah penuh"<<endl;
}
void cetak(void)//mencetak isi stack
{
for(int k=0;k<n;k++)//for(k=n-1;k>=0;k--)
{
cout<<S[k]<<"'";
}
-1-
D:\KAMPUS\MATERI KULIAH\STRUKTUR DATA\STRUKTUR DATA 3 SKS\Program\doublestack.cpp 13 Desember 2014 6:03
}
void pop1(void)
{
int k=3;//menghapus sebanyak k elemen
for(int l=0;l<k;l++)
S[top1--]='\0';
/**
while(top1>=0)
{
//top1--;
}**/
}
-2-