Contoh Program Queue

Bookmark and Share






#include<iostream.h>

char q[10];

int m=0,h=0;



void store (char c)

{    q[m]=c;

    if(m==9)m=0;

    else m++;}

char ret()

{    cout <<"result = " <<q[h]<<endl;

    if(h==9)h=0;

    else h++;}

void cetak ()

{    cout<<"queue  : ";

    if(m>h)

    {    for (int i=h;i<m;i++)

        cout<<q[i]<<"  ";

        cout<<endl;}

    else if (m<h)

    {    for (int j=h; j<10;j++)

        cout<<q[j]<<"  ";

        for(j=0;j<m;j++)

        cout<<q[j]<<"  ";}

    else

        cout<<"kosong"<<endl;

    cout<<endl;

} //end of void cetak



main()

{char x; int upil;

do {cout<<"QUEUE\n1. Store\n2. Retrieve\n3. Selesai\nPilihan Anda : ";

cin>>upil;

switch (upil)

{case 1:

{cout<<"Masukkan : ";cin>>x;store (x);cetak();break;}

case 2:

{ret();cetak();break;}

case 3:

{cout<<"Program selesai, silahkan tutup program ini.";break;}

default:

cout<<"Pilihan anda salah."<<endl<<endl;}

}

while (upil!=3);

}

{ 0 komentar... Views All / Send Comment! }

Posting Komentar

Powered By Blogger