#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); |
void dequeue(char); |
void inisialisasi(); |
void inisialisasiA(); |
void inisialisasiB(); |
void inisialisasiC(); |
void inisialisasiD(); |
void inisialisasiDequeueA(); |
void inisialisasiDequeueB(); |
|
private : |
int B[maks]; |
char A[maks]; |
int banyak; |
}; |
ostream& operator<<(ostream& out,const Queue& s){ |
cout<<"\nIsi Elemen :"; |
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 Elemen :"; |
for(int i=0;i<banyak;i++) |
cout<<A[i]<<" "; |
} |
void Queue::enqueue(char x){ |
cout<<"\nElemen masuk :"<<x; |
if(penuh(banyak))cout<<"Queue penuh"; |
else if(A[0]=='0'){ |
A[0]=x; |
banyak++; |
} |
else{ |
for(int i=banyak;i>=0;i--) |
A[i+1]=A[i]; |
A[0]=x; |
banyak++; |
} |
|
} |
void Queue::dequeue(char v){ |
char temp=A[--banyak]; |
cout<<"\nelemen yang di-dequeue :"<<temp; |
A[banyak]='0'; |
} |
void Queue::inisialisasi(){ |
int a=0; |
cout<<"Banyak elemen :"<<a<<" "<<"Depan :"<<a<<" "<<"Belakang :"<<a<<'\n'; |
} |
void Queue::inisialisasiA(){ |
int a=0; |
cout<<"Banyak elemen :"<<a+1<<" "<<"Depan :"<<a+1<<" "<<"Belakang :"<<a+1<<'\n'; |
} |
void Queue::inisialisasiB(){ |
int a=0; |
cout<<"Banyak elemen :"<<a+2<<" "<<"Depan :"<<a+1<<" "<<"Belakang :"<<a+1<<'\n'; |
} |
void Queue::inisialisasiC(){ |
int a=0; |
cout<<"Banyak elemen :"<<a+3<<" "<<"Depan :"<<a+1<<" "<<"Belakang :"<<a+1<<'\n'; |
} |
void Queue::inisialisasiD(){ |
int a=0; |
cout<<"Banyak elemen :"<<a+2<<" "<<"Depan :"<<a+3<<" "<<"Belakang :"<<a+4<<'\n'; |
} |
|
void Queue::inisialisasiDequeueA(){ |
int a=0; |
cout<<"Banyak elemen :"<<a+2<<" "<<"Depan :"<<a+2<<" "<<"Belakang :"<<a+3<<'\n'; |
} |
void Queue::inisialisasiDequeueB(){ |
int a=0; |
cout<<"Banyak elemen :"<<a+1<<" "<<"Depan :"<<a+3<<" "<<"Belakang :"<<a+3<<'\n'; |
} |
|
int main(int argc, char *argv[]) |
{ |
Queue q; |
cout<<q; |
for(int i=0;i<maks;i++) |
cout<<"0"; |
cout<<endl; |
q.inisialisasi(); |
|
|
q.enqueue('A'); |
cout<<q; |
cout<<endl; |
q.inisialisasiA(); |
|
q.enqueue('B'); |
cout<<q; |
cout<<endl; |
q.inisialisasiB(); |
|
q.enqueue('C'); |
cout<<q; |
cout<<endl; |
q.inisialisasiC(); |
|
char A; |
q.dequeue(A); |
cout<<q; |
cout<<endl; |
q.inisialisasiDequeueA(); |
|
char B; |
q.dequeue(B); |
cout<<q; |
cout<<endl; |
q.inisialisasiDequeueB(); |
|
q.enqueue('D'); |
cout<<q; |
cout<<endl; |
q.inisialisasiD(); |
system("PAUSE"); |
return EXIT_SUCCESS; |
} |
Minggu, 23 Januari 2011
Praktikum Struktur Data 8
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar