回复 5楼 qiansu
那你自己改一下嘛
程序代码:
#include <iostream>
#include <string>
using namespace std;
std::string foo( const int buf[], size_t bufsize, const std::string& prefix="" )
{
if( bufsize == 0 )
return {};
std::string result = std::to_string(buf[0]) + '\n';
for( size_t i=1; i!=bufsize; ++i )
result += prefix + (i+1!=bufsize?"├─":"└─") + foo( buf+i, bufsize-i, prefix+"│ " );
return result;
}
int main( void )
{
int a[] = { -1, 1, 2, 3, 4 };
cout << foo(a,std::size(a)) << endl;
int b[] = { -1, 1, 0 };
cout << foo(b,std::size(b)) << endl;
}