程序填空题:Selection Sort with Doubly Linked List
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
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