-->
当前位置:首页 > 题库 > 正文内容

程序填空题:Selection Sort with Doubly Linked List

Luz2年前 (2022-11-16)题库370
The function SelectionSort is to sort the doubly linked list L (with a dummy header) in non-increasing order.

The list structure is defined as the following:


typedef struct Node *PtrToNode;
struct Node{
int Data;
PtrToNode Pre, Next;
};
typedef PtrToNode List;


Please fill in the blanks.

c++
void SelectionSort( List L )
{
List tail, maxp, ptr;
tail = L;
while (tail->Next) {
ptr = maxp = tail->Next;
while (ptr) {
if () maxp = ptr;
ptr = ptr->Next;
}
if (tail->Next != maxp) {
maxp->Pre->Next = maxp->Next;
if (maxp->Next) maxp->Next->Pre = ;
maxp->Next = tail->Next;
maxp->Pre = tail;
;
tail->Next = ;
}
tail = tail->Next;
}
}









答案:
第1空:ptr->Data > maxp->Data

第2空:maxp->Pre

第3空:tail->Next->Pre = maxp

第4空:maxp

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。