4/04/2013

PERCOBAAN ANTRIAN QUEUE

| 4/04/2013 | 0 comments
sourch code:



#include <stdio.h>
#include <string.h>
#include <math.h>

#define MAX 25

typedef struct
{
        int item [MAX];
        int front;
        int rear;
        int count;
}Queue;

void InitializeQueue(Queue *Q)
{
     Q->front = 0;
     Q->rear = 0;
     Q->count = 0;
}

int EmptyQueue(Queue *Q)
{
    return (Q->count == 0);
}
int FullQueue(Queue *Q)
{
    return (Q->count==MAX);
}
void Enqueue(int x, Queue *Q)
{
     if (FullQueue(Q))
        printf ("Queue penuh!! Data tidak dapat masuk!!");
     else
     {
         Q->item [Q->rear]=x;
         Q->rear=(Q->rear+1)%MAX;
         ++(Q->count);
     }
}

int Dequeue (Queue *Q)
{
    int temp;
      if (EmptyQueue(Q))//stack kosong
      printf("Queue masih kosong!");
      else
      {
          temp=Q->item[Q->front];
          Q->front=(Q->front+1)%MAX;
          --(Q->count);
          return temp;
      }
}

int main ()
{
     Queue qk;
     int n, i, bil, hsl;

     InitializeQueue(&qk);

     printf("Jumlah Data Yang Anda Masukan Adalah : ");
     scanf("%d",&n);
     for(i=0;i<n;i++)
     {
                     printf("Masukkan data ke-%d: ",i+1);
                     scanf("%d",&bil);
                     Enqueue(bil, &qk);
     }

     printf("Isi dari Queue adalah : ");
     for(i=0;i<n;i++)
     {
                     hsl=Dequeue(&qk);
                     printf("%d",hsl);
     }
     }


output :


0 comments:

Post a Comment

 
© Copyright 2012 Decision One, move to DiJava on 16 May 2012 | Template by o-om.com | Cewek Jogja