33,311
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
void someFunction( int [], int );
int main()
{
const int arraySize = 10;
int a[ arraySize ] = { 32, 27, 64, 18 ,95, 14, 90, 70, 60, 37 };
cout << "The values in the array are: " << endl;
someFunction( a, arraySize );
cout << endl;
system("pause");
return 0;
}
void someFuntion( int b[], int size )
{
if ( size > 0 )
{
someFunction( &b[1], size - 1 ); //这里看不懂, &b[1] ?
cout << b[0] << " ";
}
}
#include <iostream>
#include<string>
#include<vector>
#include<cstring>
using namespace std;
void someFunction(int[], int );
int main()
{
const int arraySize = 10;
int a[arraySize] = { 32, 27, 64, 18 ,95, 14, 90, 70, 60, 37 };
cout << "The values in the array are: " << endl;
someFunction(a,arraySize );
cout << endl;
system("pause");
return 0;
}
void someFunction(int *p,int size )
{
if ( size > 0 )
{
someFunction(p+1, size - 1 ); //这样你应该好理解吧,跟你的程序完全等价
cout << *p << " ";
}
}
#include <iostream>
#include<string>
#include<vector>
#include<cstring>
using namespace std;
void someFunction(int[], int );
int main()
{
const int arraySize = 10;
int a[arraySize] = { 32, 27, 64, 18 ,95, 14, 90, 70, 60, 37 };
cout << "The values in the array are: " << endl;
someFunction(a,arraySize );
cout << endl;
system("pause");
return 0;
}
void someFunction(int b[],int size )
{
if ( size > 0 )
{
someFunction(&b[1], size - 1 ); // &b[1] 每一次递归,向后顺延数组一个元素,也就是说,第一次是
//传入的是a数组,第二次传入的是a+1,依次类推
cout << b[0] << " ";
}
}