Listing Program C++ Antrian Queue

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

main()
{
    int cek=0, data[20], x, hapus;
    char pil;
    do {
            clrscr();
            cout<<"1. Tambah Antrian"<<endl;
            cout<<"2. Hapus Antrian"<<endl;
            cout<<"3. Lihat Antrian"<<endl;
            cout<<"4. Keluar"<<endl;
         cout<<endl;
            cout<<"Silahkan masukkan pilihan anda = ";
            pil=getche();
         cout<<endl;
if(pil!='1' && pil !='2' && pil !='3' && pil!='4' )
          cout<<"Anda salah mengetikkan inputan";
            else
            {
                if(pil=='1')   //PUSH
                {
                    if(cek==20)
                        cout<<"Antrian Penuh";
                    else
                    {
                    cout<<"Masukkan nilai = ";
               cin>>x;
                        data[cek]=x;
                        cek++;
                    }
                }
                else
                {
                    if(pil=='2')     //POP
                    {
                        if(cek==0)
                            cout<<"Antrian kosong";
                        else
                        {
                            hapus=data[0];
                            for(int v=0;v<cek;v++)
                                data[v]=data[v+1];
                            data[cek-1]=NULL;
                            cek--;
                       cout<<"Data dengan nilai "<<hapus<<" terhapus";
                        }
                        getch();
                    }
                    else
                    {
                        if(pil=='3')   //CEK DATA
                        {
                            if(cek==0)    
                                cout<<"Antrian Kosong";

                            else
                            {
                                cout<<endl;
                                for(int z=0;z<cek;z++)
                                {
                                    cout<<" | ";
                                    cout<<" "<<data[z];
                                    cout<<" | ";
                                }

                            }
                            getch();
                        }
                    }
                }
            }

    }while(pil!='4');
}
Previous
Next Post »

4 comments

Click here for comments
Anonim
admin
8 November 2012 pukul 07.07 ×

thank's bgt neeh wt listingnya...membantu bgt u/ balajar...

Reply
avatar
Unknown
admin
21 Mei 2013 pukul 20.20 ×

thanks brothers lagi belajar ini c++ :)

Reply
avatar
Unknown
admin
24 Februari 2014 pukul 17.45 ×

makasih ya, sangat bermanfaat :)

Reply
avatar