请问各位高手这个简单程序为何无法正常工作
目的是输出排序后的数程序代码:
#include<iostream> #include<string> using namespace std; void swap(int &a, int &b) { int temp; temp = a; a = b; b = temp; } int SelectMinKey(int a[], int n, int i) { int k = i; for (int j = i + 1; j< n; ++j) { if (a[k] > a[j]) k = j; } return k; } void selectSort(int a[], int n){ int key; for (int i = 0; i< n; ++i) { key = SelectMinKey(a, n, i); //选择最小的元素 if (key != i) swap(a[i], a[key]); //最小元素与第i位置元素互换 } } void main() { int n, arr[1]; int *p=arr; cout << "Please input array number: " << endl; cin >> n; p = new int(n - 1); cout << "Please input all the integer: " << endl; for (int i = 0; i < n; i++) cin >> arr[i]; selectSort(arr, n); for (int i = 0; i < n; i++) cout << arr[i]; system("pause"); }