0% found this document useful (0 votes)
67 views9 pages

Contoh Implementasi Queue

This C program manages queues for two lines (customer service and teller) at a bank called Bank Kotan. It allows adding customers to and removing customers from the front of each line. It displays the current lines and prompts the user to select an option to add to a line, remove from a line, or exit. It uses linked lists to implement the queues and stores customer codes in each node.

Uploaded by

Aprillia Stevani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views9 pages

Contoh Implementasi Queue

This C program manages queues for two lines (customer service and teller) at a bank called Bank Kotan. It allows adding customers to and removing customers from the front of each line. It displays the current lines and prompts the user to select an option to add to a line, remove from a line, or exit. It uses linked lists to implement the queues and stores customer codes in each node.

Uploaded by

Aprillia Stevani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

/*

Nama File: bank.c

Kasus:

Mengelola antrian pada sebuah bank bernama Bank Kotan dimana

setiap nasabah yang datang akan memilih antrian: 1 antrian teller

atau 2 antrian Customer Service.

- Tampilan pertama: memperlihatkan antrian kosong, baik antrian teller

maupun antrian CS, sekaligus pilihan menu mengenai pendaftaran antrian

- Jika antrian sudah berisi, tampilkan nomor antrian untuk kedua antrian

- jika antrian sudah dilayani, hapus data dari antrian lalu tampilkan antrian

berikutnya.

- ulangi sampai selesai

berikut salah satu cara sederhana menyelesaikan kasus tersebut

*/

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

typedef struct node{

char data[10];

struct node *next;

} NODE;

NODE *frontCS;
NODE *rearCS;

NODE *frontTL;

NODE *rearTL;

void insertCS(int *n);

void deleteCS();

char *peekCS(NODE *p);

void insertTL(int *n);

void deleteTL();

char *peekTL(NODE *p);

char *kode(int *n, int i);

void main(){

int choice;

int noCS=1, noTL=1, *n;

NODE *ptr;

while(choice != 5){

system("CLS");

printf("======================================\n");

if(peekCS(ptr)!=NULL)

printf("ANTRIAN CS : %s\n", peekCS(ptr));

if(peekTL(ptr)!=NULL)
printf("ANTRIAN Teller: %s\n", peekTL(ptr));

printf("======================================\n");

printf("1. Tambah Antrian CS\n");

printf("2. Tambah Antrian Teller\n");

printf("3. Antrian CS berikutnya\n");

printf("4. Antrian Teller berikutnya\n");

printf("5. Exit\n");

printf("======================================\n");

printf("\nEnter nomor pilihan: ");

scanf("%d",& choice);

printf("======================================\n");

switch(choice){

case 1: n = &noCS;

insertCS(n);

noCS++;

break;

case 2: n = &noTL;

insertTL(n);

noTL++;

break;

case 3: deleteCS();

break;

case 4: deleteTL();

break;

case 5: exit(0);
break;

default:

printf("\nEnter pilihan yang valid...\n");

char *kode(int *n, int i){

char kd[10];

char output[4];

if(i==1)

strcpy(kd, "CS");

else

strcpy(kd, "TL");

sprintf(output, "%03d", *n);

strcat(kd, output);

return kd;

void insertCS(int *n){

NODE *ptr;

char item[10];

ptr = (NODE *) malloc (sizeof(NODE));


if(ptr == NULL){

printf("\nOVERFLOW\n");

return;

else{

printf("\nTambah Data: ");

//scanf("%s", item); fflush(stdin);

strcpy(item, kode(n, 1));

strcpy(ptr->data, item);

if(frontCS == NULL){

frontCS = ptr;

rearCS = ptr;

frontCS -> next = NULL;

rearCS -> next = NULL;

else{

rearCS -> next = ptr;

rearCS = ptr;

rearCS->next = NULL;

void insertTL(int *n){

NODE *ptr;
char item[10];

ptr = (NODE *) malloc (sizeof(NODE));

if(ptr == NULL){

printf("\nOVERFLOW\n");

return;

else{

printf("\nTambah Data: ");

//scanf("%s", item); fflush(stdin);

strcpy(item, kode(n, 2));

strcpy(ptr->data, item);

if(frontTL == NULL){

frontTL = ptr;

rearTL = ptr;

frontTL -> next = NULL;

rearTL -> next = NULL;

else{

rearTL -> next = ptr;

rearTL = ptr;

rearTL->next = NULL;

}
void deleteCS(){

NODE *ptr;

if(frontCS == NULL){

printf("\nUNDERFLOW\n");

return;

else{

ptr = frontCS;

frontCS = frontCS -> next;

free(ptr);

void deleteTL(){

NODE *ptr;

if(frontTL == NULL){

printf("\nUNDERFLOW\n");

return;

else{

ptr = frontTL;

frontTL = frontTL-> next;


free(ptr);

char *peekCS(NODE *ptr){

//NODE *ptr;

ptr = frontCS;

if(frontCS == NULL){

printf("ANTRIAN CS KOSONG...!\n");

else{

return (ptr -> data);

char *peekTL(NODE *ptr){

//NODE *ptr;

ptr = frontTL;

if(frontTL == NULL){

printf("ANTRIAN TELLER KOSONG...!\n");

else{

return (ptr -> data);


}

You might also like