Program Menggabungkan 2 Stack(Tumpukan) menjadi 1 Tumpukan

#include <iostream>

using namespace std;
class stack
{

public :
void input();
void gabung();
void output();

private:
char b[10], c[10], a[10];
int k,l;
};

void stack::input()
{
cout << "massukkan banyaknya tumpukan 1 : "; cin >> k;
for (int i=0; i<k; i++)
{cout << "masukkan elemen : "; cin >> b[i];}

cout << "massukkan banyaknya tumpukan 2 : "; cin >> l;
for (int j=0; j<l; j++)
{cout << "masukkan elemen : "; cin >> c[j];}
}

void stack::gabung()
{
int j=k-1;
int g=l;

for(int i=(k+l); i>=0; i--)
{                    
if(i<k)
{a[i]=b[j];
j--;}
else
{a[i]=c[g];
g--;}
}
cout << "isi elemen tumpukan adalah"<<endl;
for (int j =0; j< k+l; j++)
{cout << a[j]<<" ";}

}

int main ()
{

stack x;
x.input();
x.gabung();

    system("PAUSE");
    return EXIT_SUCCESS;
}


Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s