[問題] C++以函數傳送陣列,而以指標方式接收

看板Programming作者 (怎樣轉移檔案?)時間18年前 (2007/04/10 18:27), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/8 (看更多)
我想以函數傳送陣列,而以指標方式接收 不過結果卻讓人失望,附上我的原始碼, 請各位幫我看看是哪裡出了問題,謝謝! #include <iostream> using namespace std; void array_dump(int *a, int size ) { int *ptr; for ( ptr = a; ptr < (a+size) ; ptr++ ) cout << *ptr ; cout << endl;} void bubble_sort(int *a, int size) { int i,temp; int *ptr; for( i = 0 ; i < size ; i++ ) for( ptr = a; ptr < (a+size) ; ptr++ ) { if( *ptr < *(ptr+1) ) { temp=*(ptr+1); *(ptr+1)=*ptr; *ptr=temp; } array_dump(a,size); }} main () { int size; int a[5] = {21,53,60,78,89}; size=5; cout << " Bubble Sort " <<endl; array_dump( a, size ); cout << "-------------" <<endl; bubble_sort( a, size ); system("PAUSE"); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.169.106.239
文章代碼(AID): #166zSZoh (Programming)
討論串 (同標題文章)
文章代碼(AID): #166zSZoh (Programming)