Hello, I am learning c++ and I am currently at halt.
I am trying to write a function such that:
1) It takes in input a one dimensional vector and an integer which specifies a row.
2) The numbers on that row are put into an output vector for later use.
The only issue is that this online course states that I must use another function that I have made before that allows a 1d vector with one index be able to have two indexes.
it is:
1 2 3
|
int 2d_to_1d(int row, int col, int rowlen){
return row*rowlen+col;
}
|
logically what I am trying to do:
1) I use this function to store the input vector into a temporary vector as a 2D matric with i as the x axis and y as the y axis.
2) from there I have a loop which reads out the numbers on the row needed and stores it in the output vector.
so far I have:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
void row(int r, const std::vector<int>& in, std::vector<int>& out){
int rowlength = std::sqrt(in.size());
std::vector <int> temp;
for(int i = 0; i < rowlength; i++){ // i is vertical and j is horizontal
for(int j = 0; j < side; j++){
*** temp[twod_to_oned(i,j,side)];
// now stored as a 2D array(matrix?)
}
}
for(int i=r; i=r; i++){
for(int j=0; j< rowlength; j++){
*** out[temp[]]
}
}
|
I'm pretty sure there is something wrong in the first and last loop which turns into a 2D matric then stores the row.
I starred the parts that are incomplete due to my lack of knowledge.
How could I overcome this issue? I would appreciate any help, Many thanks.