c++数据结构实验链表排序

if (!p) throw \查找位置非法\; else return p; }

void LinkList::sift(int k, int m) { int i = k, j = 2 * i; while (j <= m) { comparef++; if (jdata>Get(j + 1)->data)) j++; if (Get(i)->data < Get(j)->data) break; else { turn(Get(i), Get(j)); i = j; j = 2 * i; } } }

void LinkList::heapsort(int n) { LARGE_INTEGER t1, t2, feq; QueryPerformanceFrequency(&feq); //每秒跳动次数 QueryPerformanceCounter(&t1); //测前跳动次数 for (int i = n / 2; i >= 1; i--) sift(i, n); for (int i = 1; i < n; i++) { turn(Get(1), Get(n - i + 1)); sift(1, n - i); } QueryPerformanceCounter(&t2); //测后跳动次数 double d = ((double)t2.QuadPart - (double)t1.QuadPart) / ((double)feq.QuadPart);//时间差秒 cout << \操作时间为:\ << d << endl; }

void tell(LinkList &a, LinkList &b, LinkList &c, LinkList &d, LinkList &e) { a.print(); comparef = 0; movef = 0; a.InsertSort(); cout << \排序结果:\; a.print();

cout << \插入排序法: Compare:\ << setw(3) << comparef << \ Move:\ << setw(3) << movef << endl; comparef = 0; movef = 0; b.BubbleSort(); cout << \改进型冒泡排序法: Compare:\ << setw(3) << comparef << \ Move:\ << setw(3) << movef << endl; comparef = 0; movef = 0; c.QSort(); cout << \快速排序法: Compare:\ << setw(3) << comparef << \ Move:\ << setw(3) << movef << endl; comparef = 0; movef = 0; d.SelectSort(); cout << \简单选择排序法 Compare:\ << setw(3) << comparef << \ Move:\ << setw(3) << movef << endl; comparef = 0; movef = 0; e.heapsort(10); cout << \堆排序算法 Compare:\ << setw(3) << comparef << \ Move:\ << setw(3) << movef << endl; }

联系客服:779662525#qq.com(#替换为@)