Selamat Datang Di Blogg Saya

Selasa, 06 Desember 2011

Program Antrian

#include <cstdlib>
#include <iostream>

using namespace std;
class queue{
   public:
           queue();
         void enqueue();
         void dequeue();
         void cetak();
   private:
        int antrian[30];
         int antrian1[15];
         int antrian2[15];
         int temp1[15];
         int temp2[15];
         int data, data2;
    };

   queue::queue(){
       suit:
      cout<<"Masukkan jumlah antrian (harus genap) : ";
      cin>>data;
      if(data%2==0){
          for(int i=1;i<=data;i++){
             cout<<"antrian "<<i<<" : ";
             cin>>antrian[i];
              }
      data2 = data/2;
         }
      else goto suit;
       }

   void queue::dequeue(){
      for(int j=1;j<=data2;j++){
         temp1[j]=antrian[j];
          }
      for(int k=(data2+1);k<=data;k++){
         temp2[k-data2]=antrian[k];
          }
       }

   void queue::enqueue(){
      for(int i=1;i<=data2;i++){
         antrian1[i]=temp1[i];
         antrian2[i]=temp2[i];
          }
       }

   void queue::cetak(){
      cout<<"Antrian awal : ";
      for(int i=1;i<=data;i++){
         cout<<antrian[i]<<" ";
          }
      cout<<"\nAntrian 1 : ";
      for(int i=1;i<=data2;i++){
         cout<<antrian1[i]<<" ";
          }
      cout<<"\nAntrian 2 : ";
      for(int i=1;i<=data2;i++){
         cout<<antrian2[i]<<" ";
          }
       }
int main(int argc, char *argv[])
{
    queue x;
     x.dequeue();
     x.enqueue();
     x.cetak();
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

0 comments:

Posting Komentar