对不起,我不够清楚。我要求的是比这更好的东西:
cout
//Create a sub-vector - new_vpc.
vector<PathCoordinates>::const_iterator begin=vpc.begin();
typedef PathCoordinates type;
int iFirst=problemsStartAt;//first index to copy
int iLast=problemsEndAt-1;//last index -1, 11th stays
int iLen=iLast-iFirst;//10-8=2
vector<PathCoordinates> new_vpc;
//Pre-allocate the space needed to write the data directly.
new_vpc.resize(iLen);
memcpy(&new_vpc[0],&vpc[iFirst],iLen*sizeof(PathCoordinates));
cout<<"new_vpc.size():"<<new_vpc.size()<<endl;
for(int i=0;i<new_vpc.size();i++)
{
cout<<"new_vpc[i]:"<<new_vpc[i].strt_col<<", "<<new_vpc[i].strt_row<<", "<<new_vpc[i].end_col<<", "<<new_vpc[i].end_row<<endl;
}
reverse(new_vpc.begin(),new_vpc.end());
for(int i=0;i<new_vpc.size();i++)
{
cout<<"new_vpc[i]:"<<new_vpc[i].strt_col<<", "<<new_vpc[i].strt_row<<", "<<new_vpc[i].end_col<<", "<<new_vpc[i].end_row<<endl;
}
//Add sub-vector - new_vpc to main vector - vpc.
copy_n(new_vpc.begin(),new_vpc.size(),&vpc[problemsStartAt]);
//Output
for(int i=0;i<vpc.size();i++)
{
cout<<"vpc[i]:"<<vpc[i].strt_col<<", "<<vpc[i].strt_row<<", "<<vpc[i].end_col<<", "<<vpc[i].end_row<<endl;
}
/*
Output:
Inside backTrack()8,11
vpc contains:11
vpc contains:11
new_vpc.size():2
new_vpc[i]:265, 185, 100, 105
new_vpc[i]:240, 185, 121, 125
new_vpc[i]:240, 185, 121, 125
new_vpc[i]:265, 185, 100, 105
vpc[i]:440, 288, 460, 303
vpc[i]:440, 263, 460, 225
vpc[i]:440, 238, 498, 210
vpc[i]:388, 185, 459, 155
vpc[i]:363, 185, 823, 171
vpc[i]:338, 185, 823, 425
vpc[i]:308, 185, 308, 144
vpc[i]:290, 185, 65, 193
vpc[i]:240, 185, 121, 125
vpc[i]:265, 185, 100, 105
vpc[i]:228, 700, 80, 750
*/