#include<stdio.h>
#include<stdlib.h>
typedef struct queue {
char** data;
int head, tail, size, count;
}queue;
queue* makequeue(int n) {
queue* q = (queue*)malloc(sizeof(queue));
q->data = (char**)malloc(sizeof(char*) * n);
q->head = q->tail = q->count = 0;
q->size = n;
return q;
}
int push(queue* q, char* val) {
if (q->count == q->size) return 0;
q->data[q->tail] = val;
q->tail += 1;
if (q->tail == q->size) {
q->tail = 0;
}
q->count += 1;
return 1;
}
char* pop(queue* q) {
q->head += 1;
if (q->head == q->size) q->head = 0;
q->count -= 1;
if (q->head == 0) return q->data[q->size - 1];
return q->data[q->head - 1];
}
int main() {
char sky[10][3] = { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };
char land[12][3] = { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };
queue* s = makequeue(10);
queue* l = makequeue(12);
for (int i = 0; i < 10; i++) {
push(s, sky[i]);
}
for (int i = 0; i < 12; i++) {
push(l, land[i]);
}
printf(" 天干地支表\n");
for (int i = 0; i < 60; i++) {
printf("|%02d%s%s", i + 1, pop(s), pop(l));
int flag = i + 1;
if (flag % 10 == 0) printf("|\n");
}
return 0;
}
使用队列结构打印天干地支表
最新推荐文章于 2024-08-18 08:31:43 发布