题目链接:点击打开链接
题目大意:注意这里的 Last 相当于 Pre 的意思。
解题思路:略。
AC 代码
DequeCreateDeque() { PtrToNodend=(PtrToNode)malloc(sizeof(structNode)); Dequedeq=(Deque)malloc(sizeof(structDequeRecord)); nd->Next=nd->Last=NULL; deq->Front=deq->Rear=nd; returndeq; } intPush(ElementTypeX, DequeD) { PtrToNodend=(PtrToNode)malloc(sizeof(structNode)); if(!nd) return0; nd->Element=X; nd->Last=D->Front; nd->Next=D->Front->Next; if(D->Front->Next) D->Front->Next->Last=nd; D->Front->Next=nd; if(D->Front==D->Rear) D->Rear=nd; return1; } intInject(ElementTypeX, DequeD) { PtrToNodend=(PtrToNode)malloc(sizeof(structNode)); if(!nd) returnERROR; nd->Element=X; nd->Next=NULL; D->Rear->Next=nd; nd->Last=D->Rear; if(D->Rear==D->Front) D->Front->Next=nd; D->Rear=nd; return1; } ElementTypePop(DequeD) { if(D->Front==D->Rear) returnERROR; PtrToNodend=D->Front->Next; if(D->Front->Next==D->Rear) D->Rear=D->Front; D->Front->Next=D->Front->Next->Next; ElementTypetmp; tmp=nd->Element; free(nd); returntmp; } ElementTypeEject(DequeD) { if(D->Front==D->Rear) returnERROR; PtrToNodend=D->Rear; ElementTypetmp=nd->Element; D->Rear=D->Rear->Last; free(nd); returntmp; }