數據結構實驗 實驗四 - 下載本文

//初始化排序實例 //Data:數組數據 //length:數組長度

Sort(int Data[], int length) { }

//插入排序 //out:輸出流 //key:查找的關鍵字

void InsertSort(ostream &out) { }

//快速排序 //out:輸出流 //key:查找的關鍵字

void QuickSort(ostream &out, int left, int right) {

if(left < right) { }

int pivotpos = Partition(left, right); PrintData(out, pivotpos); cout << endl;

QuickSort(out, left, pivotpos -1); QuickSort(out , pivotpos +1, right); int temp, i, j;

for(i = 1; i <= Count -1; i++) { }

if(data[i] < data[i -1])//逆序才插入位置,否則留置原位 { }

out << \第\ << i << \次排序結果:\; PrintData(out); out << endl;

temp = data[i];

for(j = i - 1; j >= 0 && temp < data[j]; j--)

data[j+1] = data[j];//逆向尋找temp插入位置 data[j+1] = temp;

Count = length;

for(int i = 0; i < length; i++) { }

data[i] = Data[i];

};

}

//輸出數組 //out:輸出流

void PrintData(ostream &out) { }

//輸出數組 //out:輸出流 //base:基準數據

void PrintData(ostream &out, int base) { }

for (int i = 0; i < Count; i++) { }

if (i == base) cout << \ << data[i] << \; else cout << data[i] << \; for(int i = 0; i < Count; i++)

out << data[i] << \;

int _tmain(int argc, _TCHAR* argv[]) { }

int toFind[] = {13, 22, 35, 43, 54, 68, 71, 82, 98, 1005}; Find f(toFind, 10); int key = 0;

cout << \請輸入查找的鍵值:\; cin >> key;

cout << \順序查找:\; f.Sequence(cout, key); cout << \折半查找:\; f.Half(cout, key); cout << endl << endl;

cout << \插入排序:\ << endl;

int toSort[] = {94,28,57,66,35,84,63,42,71,10}; Sort s(toSort, 10); s.InsertSort(cout);

cout << \快速排序:\ << endl;

int toSort2[] = {94,28,57,66,35,84,63,42,71,10}; Sort s2(toSort2, 10); s.QuickSort(cout, 0, 9); system(\); return 0;





黑龙江22选5兑奖期限