Praktikum S.Data ke-8


SIMULASI QUEUE DENGAN ARRAY
Tujuan Praktikum :
a. Mengamati penggunaan Array untuk mengimplementasikan struktur data queue
b. Mempelajari operasi-operasi pada queue

#include<cstdlib>
#include<iostream>
#define maks 6

using namespace std;

class Queue{
friend ostream& operator<<(ostream&,const Queue&);
public:
Queue();
int penuh(int);
int kosong(int);
void cetak();
void enqueue(char);
char dequeue();
void urik();
private:
char A[maks];
int banyak;
};

ostream& operator<<(ostream& out,const Queue& s)
{ cout<<"\nIsi Queue:";
for(int i=0;i<s.banyak;i++)
out<<s.A[i]<<" ";
}

Queue::Queue(){
banyak=0;
for(int i=0;i<maks;i++)
A[i]='0';
}

int Queue::penuh(int s)
{ return s==maks?1:0;}

int Queue::kosong(int s)
{ return s==0?1:0;}

void Queue::cetak()
{ cout<<"\nIsi Queue:";
for(int i=0;i<banyak;i++)
cout<<A[i]<<" ";
}

void Queue::enqueue(char x)
{
cout<<"\n\nElemen:"<<x<<" masuk antrian";
if(penuh(banyak))cout<<" \nmaaf,queue penuh!!\n"<<x<=0;i–)
A[i+1]=A[i];
A[0]=x;
banyak++;
}
}

char Queue::dequeue()
{
char temp=A[–banyak];
cout< “<<temp;
A[banyak]='0';
return temp;
}

void Queue::urik()
{
int n=maks;
char temp=A[0];
for(int i=0;i<n;i++)
A[i]=A[i+1];
A[n-1]=temp;

}

int main(int argc, char *argv[])
{
Queue q;
int x=1;
for(char c='a';c<'h';c++){
q.enqueue(c);
cout<<q;

}
char p=q.dequeue();
q.cetak();
char d='h';
q.enqueue(d);
q.urik();
cout<<q;
cout<<"\n\nCetak pakai overloading"<<q;
char r=q.dequeue();
q.cetak();

cout<<"\n\nCetak pakai overloading"<<q;

cout<<endl<<endl;;
system("PAUSE");
return EXIT_SUCCESS;
}

About Sintata
Seek and Share Knowledge

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: