入队操作时,其实就是在链表尾部插入结点,如图4-13-3所示。
    image.png
    其代码如下:

    1. /* 插入元素e为Q的新的队尾元素 */
    2. Status EnQueue(LinkQueue *Q, QElemType e){
    3. QueuePtr s = (QueuePtr)malloc(sizeof(QNode));
    4. /* 存储分配失败 */
    5. if (!s)
    6. exit(OVERFLOW);
    7. s->data = e;
    8. s->next = NULL;
    9. /* 把拥有元素e新结点s赋值给原队尾结点的后继, */
    10. Q->rear->next = s;
    11. /* 见上图中① */
    12. /* 把当前的s设置为队尾结点,rear指向s,见上图中② */
    13. Q->rear = s;
    14. return OK;
    15. }