Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * @author: ClavinJune
- */
- #include <stdio.h>
- #include <malloc.h>
- #include <string.h>
- #define MAX 10
- struct Patient{
- char name[255];
- struct Patient *next;
- };
- struct Hospital{
- char name[255];
- int totalPatient;
- struct Patient *queueHead, *queueTail;
- struct Hospital *next;
- }*head, *tail;
- struct Patient* createPatient( char name[] ){
- struct Patient* temp = (struct Patient*)malloc(sizeof(struct Patient));
- strcpy(temp->name, name);
- temp->next = NULL;
- return temp;
- };
- struct Hospital* createHospital( char name[] ){
- struct Hospital* temp = (struct Hospital*)malloc(sizeof(struct Hospital));
- strcpy(temp->name, name);
- temp->queueHead = temp->queueTail = NULL;
- int totalPatient = 0;
- temp->next = NULL;
- return temp;
- }
- void pushHospital( struct Hospital* newHospital ){
- if( !head )
- head = tail = newHospital;
- else{
- tail->next = newHospital;
- tail = newHospital;
- }
- }
- void pushPatient( struct Patient* newPatient ){
- if( !head ) return;
- struct Hospital* tempHospital = head;
- while( tempHospital->totalPatient == MAX - 1 ){
- tempHospital = tempHospital->next; //pindah rumah sakit
- }
- if( !tempHospital ) return; // rumah sakitnya penuh semua
- if( !tempHospital->queueHead ){
- tempHospital->queueHead = tempHospital->queueTail = newPatient;
- }
- else{
- tempHospital->queueTail->next = newPatient;
- tempHospital->queueTail = newPatient;
- ++tempHospital->totalPatient;
- }
- }
- void view(){
- if( !head ) return;
- struct Hospital* temp = head;
- while( temp ){
- printf("===========\n%s\n============\n", temp->name);
- struct Patient* tempQueue = temp->queueHead;
- while( tempQueue ){
- printf("%s\n", tempQueue->name);
- tempQueue = tempQueue->next;
- }
- temp = temp->next;
- }
- }
- int main( int argc, char **argv, char **env ){
- pushHospital( createHospital("A") );
- pushHospital( createHospital("B") );
- pushPatient( createPatient("A 1") );
- pushPatient( createPatient("A 2") );
- pushPatient( createPatient("A 3") );
- pushPatient( createPatient("A 4") );
- pushPatient( createPatient("A 5") );
- pushPatient( createPatient("A 6") );
- pushPatient( createPatient("A 7") );
- pushPatient( createPatient("A 8") );
- pushPatient( createPatient("A 9") );
- pushPatient( createPatient("A 10") );
- pushPatient( createPatient("B 1") );
- pushPatient( createPatient("B 2") );
- pushPatient( createPatient("B 3") );
- view();
- getchar();
- return 0;
- }
Add Comment
Please, Sign In to add comment