数据结构PTA
20:C
22:B
27:D
填空
4-2:19
4-4:66
4-5:8
5-x:不加分号
⬇:top = p->next
链队列
#include <stdio.h>
#include <stdlib.h>
#include <string.h>typedef struct QNode {char data;struct QNode *next;
} QNode;typedef struct {QNode *front;QNode *rear;
} LinkQueue;void Init(LinkQueue *l) {l->front = l->rear = (QNode *)malloc(sizeof(QNode));l->front->next = NULL;
}void Enqueue(LinkQueue *l, char elem) {QNode *p = (QNode *)malloc(sizeof(QNode));p->data = elem;p->next = NULL;l->rear->next = p;l->rear = p;
}void PrintQueue(LinkQueue *l) {if (l->front == l->rear) {printf("Head:NULL\nPop:NULL\n");return;}printf("Head:%c\n", l->front->next->data);printf("Pop:");while (l->front != l->rear) {QNode *p = l->front->next;printf("%c", p->data);l->front->next = p->next;if (l->rear == p) l->rear = l->front;free(p);}printf("\n");
}void main() {LinkQueue l;Init(&l);char s[100];scanf("%s", s);for (int i = 0; i < strlen(s); i++) {if (s[i] == '#')break;Enqueue(&l, s[i]);}PrintQueue(&l);
}