Data Structures and Algorithms (English) - 6-1 Deque(25 分)

简介: Data Structures and Algorithms (English) - 6-1 Deque(25 分)

题目链接:点击打开链接

题目大意:注意这里的 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;
}
目录
相关文章
|
存储 容器
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
222 0
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
|
机器学习/深度学习 算法
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
216 0
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
112 0
Data Structures and Algorithms (English) - 6-4 Reverse Linked List(20 分)
Data Structures and Algorithms (English) - 6-4 Reverse Linked List(20 分)
121 0
Data Structures and Algorithms (English) - 6-15 Iterative Mergesort(25 分)
Data Structures and Algorithms (English) - 6-15 Iterative Mergesort(25 分)
191 0
Data Structures and Algorithms (English) - 6-8 Percolate Up and Down(20 分)
Data Structures and Algorithms (English) - 6-8 Percolate Up and Down(20 分)
105 0
Data Structures and Algorithms (English) - 6-2 Two Stacks In One Array(20 分)
Data Structures and Algorithms (English) - 6-2 Two Stacks In One Array(20 分)
144 0
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
102 0
Data Structures and Algorithms (English) - 7-12 How Long Does It Take(25 分)
Data Structures and Algorithms (English) - 7-12 How Long Does It Take(25 分)
114 0
Data Structures and Algorithms (English) - 6-7 Isomorphic(20 分)
Data Structures and Algorithms (English) - 6-7 Isomorphic(20 分)
128 0