Friday, February 10, 2012

program Queue

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

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(){
      queue d;
      d.dequeue();
      d.enqueue();
      d.cetak();
     
      getch();
       }



download program antrian


download aplikasi perpustakaan

No comments:

Post a Comment