贴吧用户_0K649NV -
更新中....更新成功!登陆中....登录成功!加载中....加载失败!
关注数: 6 粉丝数: 130 发帖数: 1,874 关注贴吧数: 9
保存下代码,别删 # include<stdio.h> # include<stdlib.h> typedef struct Queue { char *pBase; int front; int rear; }QUEUE, *PQUEUE; void inti_man(PQUEUE); void inti_woman(PQUEUE); void en_queue_man(PQUEUE, char); void en_queue_woman(PQUEUE, char); bool full_queue_man(PQUEUE); bool full_queue_woman(PQUEUE); void traverse_queue_man(PQUEUE); void traverse_queue_woman(PQUEUE); bool empty_queue(PQUEUE); int main(int argc, char *argv[]) { QUEUE queue_man; QUEUE queue_woman; inti_man(&queue_man); en_queue_man(&queue_man, 'a'); en_queue_man(&queue_man, 'b'); en_queue_man(&queue_man, 'c'); en_queue_man(&queue_man, 'd'); traverse_queue_woman(&queue_man); inti_woman(&queue_woman); en_queue_woman(&queue_woman, 'A'); en_queue_woman(&queue_woman, 'B'); en_queue_woman(&queue_woman, 'C'); en_queue_woman(&queue_woman, 'D'); en_queue_woman(&queue_woman, 'E'); en_queue_woman(&queue_woman, 'F'); traverse_queue_woman(&queue_man); return 0; } void inti_man(PQUEUE q) { q->pBase = (char *)malloc(sizeof(char)*5); q->front = 0; q->rear = 0; } void en_queue_man(PQUEUE q, char val) { if(full_queue_man(q)) { exit(-1); } q->pBase[q->rear] = val; q->rear = (q->rear +1) % 5; } void inti_woman(PQUEUE q) { q->pBase = (char *)malloc(sizeof(char)*7); q->front = 0; q->rear = 0; } void en_queue_woman(PQUEUE q, char val) { if(full_queue_woman(q)) { exit(-1); } q->pBase[q->rear] = val; q->rear = (q->rear +1) % 7; } bool full_queue_man(PQUEUE q) { if((q->rear+1)%5 == q->front) { return true; } else { return false; } } bool full_queue_woman(PQUEUE q) { if((q->rear+1)%7 == q->front) { return true; } else { return false; } } void traverse_queue_man(PQUEUE q) { if(empty_queue(q)) { exit(-1); } while(q->front != q->rear) { printf("%d ", q->pBase[q->front]); q->front = (q->front + 1) % 5; } } void traverse_queue_woman(PQUEUE q) { if(empty_queue(q)) { exit(-1); } while(q->front != q->rear) { printf("%d ", q->pBase[q->front]); q->front = (q->front + 1) % 7; } } bool empty_queue(PQUEUE q) { if(q->front == q->rear) { return true; } else { return false; } }
1 下一页