Membagi Stack (Tumpukan) Menjadi 2 Tumpukan

#include <iostream.h>
#include <conio.h>

class stack
{

public :
void input();
void bagi();


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

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

void stack :: bagi()
{
int l=0;
for(int i=k-1; i>=k/2; i--)
{c[l]=b[i];
l++;}
cout << "isi elemen tumpukan hasil"<<endl;
for(int l=0; l<k/2; l++)
{cout << c[l]<<" ";}

cout << endl<<"isi tumpukan "<<endl;

for(int l=0; l<=k/2; l++)
{cout << b[l]<<" ";}
}

int main ()
{

stack x;
x.input();
x.bagi();

getch();
return 0;
}

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