1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
bool en_queue(QUEUE *phead,int val){ if (full_queue(phead)) return false; phead->pBase[phead->rear] = val; phead->rear = (phead->rear + 1) % 6; return true; }
bool de_queue(QUEUE *phead, int *val){ if (is_timy(phead)) return false; *val = phead->pBase[phead->front]; phead->front = (phead->front + 1) % 6; return true; }
bool is_timy(QUEUE *phead){ if (phead->front == phead->rear) return true; return false; }
bool full_queue(QUEUE * phead){ if (phead->front==(phead->rear+1)%6) return true; return false; }
void taverse_queue(QUEUE *); void taverse_queue(QUEUE * phead){ int f = phead->front; int r = phead->rear; if (is_timy(phead)) return; while (f!=r) { printf("%dn", phead->pBase[f]); f = (f + 1) % 6; } }
void main(){ QUEUE queue; int val; init_queue(&queue); if (is_timy(&queue)) printf("空队列"); en_queue(&queue, 1); en_queue(&queue, 2); en_queue(&queue, 3); en_queue(&queue, 4); en_queue(&queue, 5); taverse_queue(&queue); if (full_queue(&queue)) printf("饱和"); en_queue(&queue, 6); if (full_queue(&queue)) printf("饱和"); de_queue(&queue, &val); de_queue(&queue, &val); de_queue(&queue, &val); de_queue(&queue, &val); de_queue(&queue, &val); de_queue(&queue, &val); taverse_queue(&queue); de_queue(&queue, &val); printf("%d", val);
}
|
近期评论