插入新元素e的的算法(1) LinkQueue En Queue LinkQueue Q, ElemType e) I Qnode *p 说明变量p )=( Qnode*)ma1loc(LENG);//生成新元素结点 p->data=e //装入元素e p->next=NULL; //为队尾结点 Q. rear->next=p //插入新结点 Q rear=p; /修改尾指针 return Q: //返回Q的新值 main LinkQueue que 米定义一个队列来/ que=InitQueueo que=EnQueue(que) 10)
插入新元素e的的算法(1) LinkQueue EnQueue(LinkQueue Q, ElemType e) { Qnode *p; //说明变量p p=(Qnode *)malloc(LENG); //生成新元素结点 p->data=e; //装入元素e p->next=NULL; //为队尾结点 Q.rear->next=p; //插入新结点 Q.rear=p; //修改尾指针 return Q; //返回Q的新值 } main() { LinkQueue que; /*定义一个队列*/ que=InitQueue(); que=EnQueue(que,10); }
插入新元素e的的算法{ int EnQueue(LinkQuelue *Q, ElemType e) i Qnode *p; //说明变量p p=( Qnode *)mallOc(LENG; //生成新元素结点 if(!p){ printf(“ OVERFLOW);//新结点生成失败 return ERROR p->data=e //装入元素e p->next=NULL //为队尾结点 Q->>next=p //插入新结点 Q->rear=p /修改尾指针 return OK: //成功返回 main LinkQueue que /*定义一个队列来/ que=InitQueueo EnQueue &que, 1o)
插入新元素e的的算法(2) int EnQueue(LinkQueue *Q, ElemType e) { Qnode *p; //说明变量p p=(Qnode *)malloc(LENG); //生成新元素结点 if (!p) {printf(“OVERFLOW”); //新结点生成失败 return ERROR;} p->data=e; //装入元素e p->next=NULL; //为队尾结点 Q->rear->next=p; //插入新结点 Q->rear=p; //修改尾指针 return OK; //成功返回 } main() { LinkQueue que; /*定义一个队列*/ que=InitQueue(); EnQueue(&que,10); }
5.出队一删除队头结点 (1)若原队列有2个或2个以上的结点 P Q front a rear 表头结点队头结点 (a)执行:Q. front->next=p->next; Q. front Q rear 目 al 表头结点队头结点 (b)执行:free(p); Q. fron rear 目L a2+ 表头结点队头结点
5.出队----删除队头结点 (1)若原队列有2个或2个以上的结点 /// 表头结点 a1 队头结点 Q.front a2 ... Q.rear P /// 表头结点 a1 队头结点 Q.front a2 ... Q.rear P (a)执行:Q.front->next=p->next; (b)执行:free(p); /// 表头结点 队头结点 Q.front a2 ... Q.rear P X
(2)若原队列只有1个结点 Q front Q rear ///∧ a1∧ 表头结点 队头结点 (a)执行:Q. front->next=p->next; Q front Q. 日 ∧ ∧ rear 表头结点队头结点 (b)执行:free(p); Q. front rear ∧ 表头结点 (c)执行:Q.rear=Q. front; Q. front Q s rear 表头结点
(2)若原队列只有1个结点 /// ∧ 表头结点 a1 ∧ 队头结点 Q.front Q.rear P (a)执行:Q.front->next=p->next; /// ∧ 表头结点 a1 ∧ 队头结点 Q.front Q.rear P (b)执行:free(p); /// ∧ 表头结点 Q.front Q.rear P /// ∧ 表头结点 Q.front Q.rear (c)执行:Q.rear=Q.front; X X X X