Program Queue Memakai Linked List


#include “stdio.h”
#include “stdlib.h”
#include “conio.h”
struct node{
int info;
struct node *next;
};
typedef struct node *simpul;

void main()
{
simpul baru, front=NULL, rear=NULL, temp;
int pilih;

do
{
printf(“MENU\n”);
printf(“1. ENQUEUE\n”);
printf(“2. VIEW\n”);
printf(“4. DEQUEUE\n”);
printf(“PILIH: “);
scanf(“%d”, &pilih);
switch(pilih)
{
case 1:
int data;
printf(“Data Masuk: “);
scanf(“%i”, &data);
baru = (simpul) malloc(sizeof (struct node));
baru->info = data;
baru->next = NULL; //tidak menuju simpul mana2
if (front == NULL) //khusus simpul pertama LL
{ front = baru;
rear = baru;
}
else //untuk simpul2 berikutnya
{ rear->next = baru;
rear = baru;
}
break;
case 2:
temp = front; //tampilkan mulai dr depan
while(temp!=NULL) //ulangi sampai temp NULL
{ printf(“%i “, temp->info);
temp = temp->next; //geser temp ke belakang
}
printf(“\n”);
break;
case 4:
if(front != NULL)
{ temp = front;
printf(“Data keluar = %d\n”, temp->info);
front = temp->next;
free(temp);
printf(“\n”);
}
else printf(“Queue sudah kosong!\n”);
break;
}
}while (pilih!=5);
}

3 Responses to Program Queue Memakai Linked List

  1. m541d says:

    Terimah kasih Pak sudah mengupload programnya………….

  2. cex says:

    hasil run nya kurang bro ;D

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: