[問題] C++以函數傳送陣列,而以指標方式接收
我想以函數傳送陣列,而以指標方式接收
不過結果卻讓人失望,附上我的原始碼,
請各位幫我看看是哪裡出了問題,謝謝!
#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
討論串 (同標題文章)
完整討論串 (本文為第 1 之 8 篇):