Re: [問題] 結果不如預期(幫Debug)
看板C_and_CPP (C/C++)作者POSIX (tedium of chores)時間16年前 (2009/03/18 23:53)推噓0(0推 0噓 0→)留言0則, 0人參與討論串2/2 (看更多)
call by value
call by address
※ 引述《kumusou (一心想)》之銘言:
: 以下是快速排序
: 但不知為啥執行後 就是沒排序
: 不知錯在哪裡
: 煩請不吝賜教 謝謝
: #include <iostream>
: using namespace std;
: void QuickSort(int *, int , int);
: void Swap(int , int);
: int main(){
: cout << "QuickSort!!\nEnter the unsorted lists's size:";
: int size = 0;
: cin >> size;
: int *a = new int [size];
: cout << "The list:";
: for(int i = 0; i < size; i++){
: cin >> a[i];
: }
: QuickSort(a, 0, size-1);
: cout << "The output:";
: for(int i = 0; i < size; i++) cout << a[i] << " ";
: cout << endl;
: delete []a;
: system("pause");
: return 0;
: }
void Swap(int* a, int *b){
int temp = *a;
*a = *b;
*b = temp;
}
: void QuickSort(int *a, int left, int right){
: if(left < right){
: int key = a[right];
: int i = left - 1;
: for(int j = left; j < right; j++){
: if(a[j] <= key){
: i++;
Swap(&a[i], &a[j]);
: }
: }
Swap(&a[i+1], &a[right]); i++;
: QuickSort(a, left, i-1);
: QuickSort(a, i+1, right);
: }
: }
--
正是在現實生活中拼搏,夢想才有意義
只是把自己投射到別人的夢想裡的話
跟死又有什麼兩樣
『真是一個現實主義者啊』
如果你把逃避現實叫做浪漫的話.....
Kusanagi Motoko草薙素子
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.117.176.163
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章
13
23