Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- #include<string.h>
- int position1=0;
- int position2=0;
- int length=1;
- typedef struct Node
- {
- int record;
- int CardNum;
- char CustomerType[20];
- struct Node* next;
- }Node;
- typedef struct queue
- {
- Node* front;
- Node* rear;
- }Queue;
- Queue q1,q2;
- void Enqueue(Queue *q, int x, char *y, int position);
- void Dequeue(Queue *q);
- void List(Queue *q);
- int main()
- {
- q1.front=NULL;
- q2.front=NULL;
- q1.rear=NULL;
- q2.rear=NULL;
- char command[10];
- int card;
- char client[10],*ptrclient;
- while(1)
- {
- scanf("%s",command);
- if(strcmp(command,"IN") == 0)
- {
- printf("IN:");
- scanf("%d",&card);
- scanf("%s",client);
- ptrclient=&client[0];
- if(strcmp(client,"VIP")==0)
- {
- //printf("Entered if VIP");
- Enqueue(&q1,card,client,position1);
- position1++;
- }
- else if(strcmp(client,"Ordinary")==0)
- {
- //printf("Entered if Ordinary");
- Enqueue(&q2,card,client,position2);
- position2++;
- }
- }
- else if(strcmp(command,"OUT") == 0)
- {
- if(q1.front == NULL && q1.rear == NULL && q2.front == NULL && q2.rear == NULL)
- {
- printf("FAILED:n");
- }
- else if(strcmp(q1.front->CustomerType,"VIP")==0)
- {
- Dequeue(&q1);
- position1--;
- }
- else if(strcmp(q2.front->CustomerType,"Ordinary")==0)
- {
- Dequeue(&q2);
- position2--;
- }
- }
- else if(strcmp(command,"LIST") == 0)
- {
- printf("LIST:n");
- List(&q1);
- List(&q2);
- }
- else if(strcmp(command,"QUIT") ==0)
- {
- printf("GOOD BYE!n");
- break;
- }
- }
- return 0;
- }
- void Enqueue(Queue *q, int x, char *y, int position)
- {
- Node* temp = (Node*)malloc(sizeof(Node));
- temp->CardNum=x;
- strcpy(temp->CustomerType,y);
- temp->record=length;
- temp->next=NULL;
- if(q->front == NULL && q->rear == NULL)
- {
- q->front=q->rear=temp;
- }
- else
- {
- q->rear->next=temp;
- q->rear=temp;
- }
- printf("%d %d %s %dn",temp->record,temp->CardNum,temp->CustomerType,position);
- length++;
- }
- void Dequeue(Queue *q)
- {
- Node* temp;
- temp=q->front;
- if(q->front == q->rear)
- {
- q->front = q->rear = NULL;
- printf("OUT:%d %d %sn",temp->record,temp->CardNum,temp->CustomerType);
- }
- else
- {
- q->front = q->front->next;
- printf("OUT:%d %d %sn",temp->record,temp->CardNum,temp->CustomerType);
- }
- free(temp);
- }
- void List(Queue *q)
- {
- Node *temp;
- if(q->front != NULL)
- {
- temp = q->front;
- while(temp != NULL)
- {
- printf("%d %d %sn",temp->record,temp->CardNum,temp->CustomerType);
- temp = temp->next;
- }
- }
- }
Add Comment
Please, Sign In to add comment