Advertisement
kadoel

C++ QUEUE

Apr 29th, 2011
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <conio.h>
  3.  
  4. main()
  5. {
  6.     int cek=0, data[20], x, hapus;
  7.     char pil;
  8.     do {
  9.             clrscr();
  10.             cout<<"1. Tambah Antrian"<<endl;
  11.             cout<<"2. Hapus Antrian"<<endl;
  12.             cout<<"3. Lihat Antrian"<<endl;
  13.             cout<<"4. Keluar"<<endl;
  14.          cout<<endl;
  15.             cout<<"Silahkan masukkan pilihan anda = ";
  16.             pil=getche();
  17.          cout<<endl;
  18. if(pil!='1' && pil !='2' && pil !='3' && pil!='4' )
  19.           cout<<"Anda salah mengetikkan inputan";
  20.             else
  21.             {
  22.                 if(pil=='1')   //PUSH
  23.                 {
  24.                     if(cek==20)
  25.                         cout<<"Antrian Penuh";
  26.                     else
  27.                     {
  28.                     cout<<"Masukkan nilai = ";
  29.                cin>>x;
  30.                         data[cek]=x;
  31.                         cek++;
  32.                     }
  33.                 }
  34.                 else
  35.                 {
  36.                     if(pil=='2')     //POP
  37.                     {
  38.                         if(cek==0)
  39.                             cout<<"Antrian kosong";
  40.                         else
  41.                         {
  42.                             hapus=data[0];
  43.                             for(int v=0;v<cek;v++)
  44.                                 data[v]=data[v+1];
  45.                             data[cek-1]=NULL;
  46.                             cek--;
  47.                        cout<<"Data dengan nilai "<<hapus<<" terhapus";
  48.                         }
  49.                         getch();
  50.                     }
  51.                     else
  52.                     {
  53.                         if(pil=='3')   //CEK DATA
  54.                         {
  55.                             if(cek==0)   
  56.                                 cout<<"Antrian Kosong";
  57.  
  58.                             else
  59.                             {
  60.                                 cout<<endl;
  61.                                 for(int z=0;z<cek;z++)
  62.                                 {
  63.                                     cout<<" | ";
  64.                                     cout<<" "<<data[z];
  65.                                     cout<<" | ";
  66.                                 }
  67.  
  68.                             }
  69.                             getch();
  70.                         }
  71.                     }
  72.                 }
  73.             }
  74.  
  75.     }while(pil!='4');
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement