RSS

Pratikum 5


PRAKTIKUM STRUKTUR DATA 5
QUEUE

Queue adalah Serangkaian nilai, dimana  item yang paling awal ditambahkan ke queue merupakan yang paling awal dihapus(First In First Out (FIFO) /First Come First Served (FCFS))

Operasi Queue
        Initialize
        Enqueue
        Dequeue
        Empty
        Full

Contoh Program Queue:

#define MAX_QUEUE_SIZE 5

typedef struct {
 int key;
} element;

void initialize( int* front, int* length ) /* Initialize the queue */
{
  *front = *length = 0;
}

int queueempty( int length ) /* Check queue empty */
{
  return length == 0;
}

int queuefull( int length )/* Check queue full */
{
  return length == MAX_QUEUE_SIZE;
}

void enqueue( int front, int* length, element queue[], element item )
{
  int where;
  if ( !queuefull( *length ) ) {
         where = front + *length;
         queue[ where % MAX_QUEUE_SIZE ] = item;
         (*length)++;
  }
}

element dequeue( int* front, int* length, element queue[] )
{
  int where;
  if ( !queueempty( *length ) ){
       where = *front;
       *front = (where+1) % MAX_QUEUE_SIZE;
      (*length)--;
       return queue[where];
  }
}

void printqueue ( element queue[], int front,  int length )
{
   int i;
   for (i=0; i<length; i++)
      printf("%d ",queue[(front+i) % MAX_QUEUE_SIZE].key);
   printf(”\n");
}

void main(void)
{
    element queue[MAX_QUEUE_SIZE];
    int front, length;
    element item;
    int i;

    initialize(&front, &length);
    item.key = 0;

    for (i=0; i<MAX_QUEUE_SIZE; i++) {
      enqueue(front, &length, queue, item);
      item.key++;
      printqueue(queue, front, length);
    }

    for (i=0; i<MAX_QUEUE_SIZE; i++) {
      printqueue(queue, front, length);
      item = dequeue(&front, &length, queue);
    }
}


TUGAS:

Buatlah program untuk simulasi antrian registrasi mahasiswa. Yang tercatat adalah nim dan nama mahasiswa. Tambahkan fitur untuk mengetahui urutan antrian dari nim tertentu.


Silahkan download File ini Klik di sini...

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 komentar:

Posting Komentar