向足够大的有序数组a中,插入有序数组b,依然有序
报错我的函数必须有返回值可是我的函数不是已经有返回值了吗?
#include<iostream>
using namespace std;
void insertArraySort(int* a, int length1, int* b, int length2)
{
int length = length1 + length2;
int indexOfA = length1 - 1;
int indexOfB = length2 - 1;
int indexOfNew = length - 1;
if (a == nullptr || b == nullptr || length1 <= 0 || length2 <= 0)
return;
while (indexOfB >= 0)
{
if (b <= a && b > a)
{
a = b;
indexOfB--;
}
else
{
a = a;
}
}
}
void main()
{
int a = { 1, 2, 3, 5, 7 };
int b = { 2,4,7,9 };
insertArraySort(a, 5, b, 4);
cout << a << endl;
} main函数必须返回int类型的值:
#include<iostream>
using namespace std;
void insertArraySort(int* a, int length1, int* b, int length2)
{
int length = length1 + length2;
int indexOfA = length1 - 1;
int indexOfB = length2 - 1;
int indexOfNew = length - 1;
if (a == nullptr || b == nullptr || length1 <= 0 || length2 <= 0)
return;
while (indexOfB >= 0)
{
if (b <= a && b > a)
{
a = b;
indexOfB--;
}
else
{
a = a;
}
}
}
int main()
{
int a = { 1, 2, 3, 5, 7 };
int b = { 2,4,7,9 };
insertArraySort(a, 5, b, 4);
cout << a << endl;
return 0;
} int main
才能return 0 根据你使用的编译器决定的
页:
[1]