Professional Documents
Culture Documents
20210328201343BN001768386
20210328201343BN001768386
h>
#include<stdlib.h>
#include<string.h>
struct obat{
char nama[50];
char resep[100];
struct obat *next;
}*head = NULL, *tail = NULL, *head2 = NULL, *tail2 = NULL;
void insert(char nama[], char resep[]){
struct obat *newObat = (struct obat*)malloc(sizeof(struct obat));
strcpy(newObat->nama, nama);
strcpy(newObat->resep, resep);
newObat->next = NULL;
if(head == NULL){
head = newObat;
tail = newObat;
}
else{
tail->next = newObat;
tail = newObat;
}
}
void pop_head(){
if(head != NULL){
struct obat *temp = head;
if(head == tail){
head = NULL;
tail = NULL;
}
else{
head = head->next;
}
free(temp);
}
}
void pop_mid(){
if(head != NULL){
if(head->next != NULL){
struct obat *temp = head->next;
head->next = temp->next;
temp->next = NULL;
free(temp);
}
}
}
void view_all_antrian(){
struct obat *curr = head;
if(curr == NULL){
printf("Tidak ada obat!\n");
return;
}
while(curr != NULL){
printf("[%s | %s]\n", curr->nama, curr->resep);
curr = curr->next;
}
}
void print_obat_selesai(char nama[]){
printf("Obat berikut selesai diracik\n");
struct obat *newObat = (struct obat*)malloc(sizeof(struct obat));
strcpy(newObat->nama, nama);
newObat->next = NULL;
if(head2 == NULL){
head2 = newObat;
tail2 = newObat;
}
else{
tail2->next = newObat;
tail2 = newObat;
}
struct obat *curr = head2;
if(curr == NULL){
printf("Tidak ada obat!\n");
return;
}
while(curr != NULL){
printf("[%s]\n", curr->nama);
curr = curr->next;
}
}
void tangani_obat(){
printf("Obat yang dilayani:\n");
view_all_antrian();
struct obat *apoteker1 = head;
struct obat *apoteker2 = head->next;
char nama[50];
printf("%s , %s sedang ditangani\n", apoteker1->nama, apoteker1->resep);
printf("%s , %s sedang ditangani\n", apoteker2->nama, apoteker2->resep);
if(head == NULL){
head = newObat;
tail = newObat;
}
else{
tail->next = newObat;
tail = newObat;
}
}
void pop_head(){
if(head != NULL){
if(head != tail){
printf("Proses obat? [y/n] : ");
scanf(" %c", &answer);
if(answer == 'y'){
tangani_obat();
}
}
}
confirm_done();
}
void option1(){
char nama[50];
char resep[100];
int main() {
int choice;
do{
system("cls");
menu();
printf(">> ");
scanf("%d", &choice);
switch (choice){
case 1 :
printf("1. Masuk obat baru\n");
option1();
break;
case 2 :
printf("2. Proses obat\n");
option2();
break;
case 3 :
printf("3. Obat selesai di proses\n");
view_all_antrian(head2);
break;
case 4:
printf("4. Tampilkan antrian obat\n");
view_all_antrian(head);
break;
default :
break;
}
system("pause");
}while (choice != 0);
return 0;
}