From 5604e1377df1ca3ab189bc114eeb5e41227db13f Mon Sep 17 00:00:00 2001 From: lihaha <1902278070@qq.com> Date: Tue, 19 Mar 2024 23:29:26 +0800 Subject: [PATCH] =?UTF-8?q?lihaha.txt=20=E8=88=9E=E4=BC=B4=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20=E6=A0=88.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 舞伴问题 栈.cpp | 122 ------------------------------------------- 1 file changed, 122 deletions(-) delete mode 100644 舞伴问题 栈.cpp diff --git a/舞伴问题 栈.cpp b/舞伴问题 栈.cpp deleted file mode 100644 index 415ab01..0000000 --- a/舞伴问题 栈.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include -#include - -typedef struct { - char name[20]; - char sex; -} DataType; - -struct Node { - DataType data; - struct Node* next; -}; -typedef struct Node *PNode; -struct Queue -{ - PNode f; - PNode r; -}; -typedef struct Queue *LinkQueue; -LinkQueue SetNullQueue_Link() -{ - LinkQueue lqueue; - lqueue = (LinkQueue)malloc(sizeof(struct Queue)); - if (lqueue != NULL) - { - lqueue->f = NULL; - lqueue->r = NULL; - } - else - printf("Alloc failure! \n"); - return lqueue; -} - -int IsNullQueue_link(LinkQueue lqueue) -{ - return (lqueue->f == NULL); -} - -void EnQueue_link(LinkQueue lqueue, DataType x) -{ - PNode p; - p = (PNode)malloc(sizeof(struct Node)); - if (p == NULL) - printf("Alloc failure!"); - else { - p->data = x; - p->next = NULL; - if (lqueue->f == NULL) - { - lqueue->f = p; - lqueue->r = p; - } - else - { - lqueue->r->next = p; - lqueue->r = p; - } - } -} -void DeQueue_link(LinkQueue lqueue) -{ - struct Node * p; - if (lqueue->f == NULL) - printf("It is empty queue!\n "); - else - { - p = lqueue->f; - lqueue->f = lqueue->f->next; - free(p); - } -} -DataType FrontQueue_link(LinkQueue lqueue) -{ - if (lqueue->f == NULL) - { - printf("It is empty queue!\n"); - } - else - return (lqueue->f->data); -} - -void DancePartner(DataType dancer[], int num) -{ - LinkQueue Queue_head = SetNullQueue_Link(); - - for (int i = 0; i < num; i++) - { - - if (!IsNullQueue_link(Queue_head) && - (FrontQueue_link(Queue_head).sex) != dancer[i].sex) - { - if (dancer[i].sex == 'F') - printf("%s %s\n", dancer[i].name, Queue_head->f->data.name); - else - { - printf("%s %s\n", Queue_head->f->data.name, dancer[i].name); - } - DeQueue_link(Queue_head); - } - else - { - EnQueue_link(Queue_head, dancer[i]); - } - } - printf("\n"); - - if (!IsNullQueue_link(Queue_head)) - { - printf("%s", Queue_head->f->data.name); - } -} - - - -int main() -{ - DataType dancer[9]; - for (int i = 0; i < 9; i++) - scanf("%s %c", dancer[i].name, &dancer[i].sex); - DancePartner(dancer, 9); - return 0; -}