using namespace std;
void swap(int list[], int m, int n)
{
int temp;
temp = list[m];
list[m] = list[n];
list[n] = temp;
}
void recurrence(int list[],int i, int j)
{
if (i == j)
{
for (int t = 0; t <= j; t++)
{
cout << list[t];
}
cout << endl;
}
else
{
for (int t = i; t <= j; t++)
{
swap(list, i, t);
recurrence(list, i + 1, j);
swap(list, i, t);
}
}
}
int main()
{
/*
int b;
cout << "请输入总的个数:\n" << endl;
cin >> b;
int *a = new int[b];
recurrence(a, 0, b-1);
delete[]a;
*/
int *a;
int b;
cout << "请输入总的个数:\n" << endl;
cin >> b;
a = (int*)malloc(b*sizeof(int));
recurrence(a, 0, b - 1);
system("pause");
return 0;
}
我的运行结果是一串的负数
I didn’t look at it very carefully. But the array a you came out with
malloc
has neither user input nor initialization, and its values are random.a = (int)malloc(bsizeof(int));
recurrence(a, 0, b - 1);
Please insert this paragraph