PROGRAM QUEUE

Standar

 CONTOH PROGRAM QUEUE

 #include <stdio.h>

#include <conio.h>

#define MAX 8

typedef struct{

int data[MAX];

int head;

int tail;

} Queue;

Queue antrian;

void Create(){

antrian.head=antrian.tail=-1;

}

int IsEmpty(){

if(antrian.tail==-1)

return 1;

else

return 0;

}

int IsFull(){

if(antrian.tail==MAX-1) return 1;

else return 0;

}

void Enqueue(int data){

if(IsEmpty()==1){

antrian.head=antrian.tail=0;

antrian.data[antrian.tail]=data;

printf(“%d masuk!”,antrian.data[antrian.tail]);

} else

if(IsFull()==0){

antrian.tail++;

antrian.data[antrian.tail]=data;

printf(“%d masuk!”,antrian.data[antrian.tail]);

}

}

int Dequeue(){

int i;

int e = antrian.data[antrian.head];

for(i=antrian.head;i<=antrian.tail-1;i++){

antrian.data[i] = antrian.data[i+1];

}

antrian.tail–;

return e;

}

void Clear(){

antrian.head=antrian.tail=-1;

printf(“data clear”);

}

void Tampil(){

if(IsEmpty()==0){

for(int i=antrian.head;i<=antrian.tail;i++){

printf(“%d “,antrian.data[i]);

}

}else printf(“data kosong!\n”);

}

int main(){

int pil;

int data;

Create();

do{

printf(“1. Enqueue\n”);

printf(“2. Dequeue\n”);

printf(“3. Tampil\n”);

printf(“4. Clear\n”);

printf(“5. Exit\n”);

printf(“Pilihan = “);scanf(“%d”,&pil);

switch(pil){

case 1: printf(“Data = “);scanf(“%d”,&data);

Enqueue(data);

break;

case 2: printf(“Elemen yang keluar : %d”,Dequeue());

break;

case 3: Tampil();

break;

case 4: Clear();

break;

}

getch();

} while(pil!=5);

}

Outputnya di coba sndiri aja yah….. 

Penulis : Agus Darmawan

2 responses »

  1. aku ada tugas kaya gini nich,,,bantuin ngerjain dunkk…

    Buatlah program antrian persewaan VCD,
    dengan ketentuan:
    1. Gunakan record VCD dengan field
    Kode_VCD, Judul, Harga_Sewa
    2. Proses enqueue digunakan untuk menambah
    data antrian, setiap ada orang mengantri
    dimasukkan data vcd apa yang mau ditonton
    (memasukkan kodevcd,judul, dan harga)
    3. Proses dequeue akan mengeluarkan data,
    menampilkan isi record (kodevcd,judul, dan harga)
    serta membuat bertambahnya variabel KAS.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s