程序填空题:Selection Sort with Doubly Linked List
The function SelectionSort is to sort the doubly linked list L (with a dummy header) in non-decreasing 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, minp, ptr;
List t;
tail = L;
while (tail->Next) {
ptr = minp = tail->Next;
while (ptr) {
if () minp = ptr;
ptr = ptr->Next;
}
if (tail->Next != minp) {
minp->Pre->Next = minp->Next;
if (minp->Next) minp->Next->Pre = ;
minp->Next = tail->Next;
minp->Pre = tail;
tail->Next->Pre = ;
;
}
tail = tail->Next;
}
}
答案:
第1空:ptr->Data < minp->Data
第2空:minp->Pre
第3空:minp
第4空:tail->Next = minp
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, minp, ptr;
List t;
tail = L;
while (tail->Next) {
ptr = minp = tail->Next;
while (ptr) {
if () minp = ptr;
ptr = ptr->Next;
}
if (tail->Next != minp) {
minp->Pre->Next = minp->Next;
if (minp->Next) minp->Next->Pre = ;
minp->Next = tail->Next;
minp->Pre = tail;
tail->Next->Pre = ;
;
}
tail = tail->Next;
}
}
答案:
第1空:ptr->Data < minp->Data
第2空:minp->Pre
第3空:minp
第4空:tail->Next = minp