Quee

What is Quee? for you who study in Informatics Engineering, Computer Sciency must have known about Quee, mustn't you. Ya.., Quee menggunakan konsep antrian FIFO (Fisrt in First Out), contoh real is easy..lihat antrian pembelian tiket kereta api yang manual ya..itu konsep Quee. Berikut diberikan contoh implementasi program Quee di C++ dengan method untuk AddQuee, DeleteQuee, DisplayElement, DisplayHeadTail. Materi lengkapnya sudah ane share buat para mahasiswa karyawan ya..coba di learnt, and discuss dipertemuan berikutnya jika ada yang didiskusikan, Now..here is the code please code manually, don't copy and paste :) to make us more understand about the code.

#include <iostream>

using namespace std;
struct node{
  int data;
  node *next;
};

class Queue{
  private:
    node *head;
    node *tail;
  public:
    Queue();

  void AddQueue(int i);
  void DelQueue();
  void CetakElement();
  void CetakHeadTail();
};

Queue::Queue()
{
  head = NULL;
  tail = NULL;
}
void Queue::AddQueue(int i)
{
  node *temp;
  temp = new node;
  temp->data = i;
  temp->next = NULL;
if( head == NULL)
{
  head = temp;
  tail = temp;
}
else{
  tail->next = temp;
  tail= temp;
  }
}

void Queue::DelQueue()
{
  node *temp;
  if(head != NULL)
{
  temp = head;
  head = head->next;
  delete temp;
  cout<<"Head di remove";
}
else
{
  cout<<"Queue Kosong"<<endl;
  }
}



void Queue::CetakElement()
{
  node *temp;
  if( head == NULL)
{
  cout<<"Queue Kosong"<<endl;
}
else
{
  temp = head;
  while( temp != tail)
{
  cout << temp->data<<"\n";
  temp = temp->next;
  }
 }
}
void Queue::CetakHeadTail()
{
  if(head != NULL)
{
  cout<<"Head: "<< head->data <<endl;
  cout<<"Tail: "<< tail->data <<endl;
}
else
  cout<<"Queue Kosong"<<endl;
}

int main()
{
  Queue q;
  int temp;
  int pilihan;
  while(1)
{
cout<<"********Queue**********"<<endl;
cout<<"1.AddQueue"<<endl;
cout<<"2.DelQueue"<<endl;
cout<<"3.Cetak Head and Tail"<<endl;
cout<<"4.Cetak All Data"<<endl;
cout<<"5.Keluar"<<endl;
cout<<"Masukan Pilihan :";
cin>>pilihan;
switch(pilihan)
  {cout<<endl;
  case 1:
    cout<<"Insert Data:"<<endl;
    cin>>temp;
    q.AddQueue(temp);
  break;
  case 2:
    q.DelQueue();
  break;
  case 3:
    q.CetakHeadTail();
  break;
  case 4:
    q.CetakElement();
  break;
  case 5:
    return 0;
}

}

return 0;
}

Popular posts from this blog

Introduction to Use Case Diagram - Case study: Facebook

Kenapa tidak berkurban?

Sequential Search