这个程序有什么问题,为什么是错误的?

#include
using namespace std;

void swap(int x, int y)
{
int z = x;
x = y;
y = z;
}

int main()
{
int shu[] = { 3, 0, 2, 1, 7, 11, 9, 4, 1, 6 };
for (int i = 0; i < 10; i++)
{
int n = i;
for (int j = i + 1; j < 10; j++)
{
if (shu[j] < shu[n]) n = j;
}
swap(shu[i], shu[n]);
}
for (int i = 0; i < 10; i++)
cout << shu[i] << endl;
}

void swap(int x, int y)
->
void swap(int& x, int& y)
看看

http://codepad.org/gRYnz3jt

Output:

0
1
1
2
3
4
6
7
9
11

楼上说的对 ,要用引用。用了引用你对这两个数的交换才能实践到你的原数组中。另外不用引用用指针也可以。