1

My apologies for the title, I did not know of a better one.

So, basically, I have a 1D vector, which I extract 256 pieces of data from this, until there is no more data left.

std::size_t begin = 0;
std::size_t nextEnd = 0;        

while (nextEnd < signal.size()) {
  begin = nextEnd;
  nextEnd += 256; 
  Transform(signal, begin, std::min(nextEnd, signal.size()));
}

Inside the "Transform" function, there is a new, temp vector created called temp_vector and inside my main I have a global 1D vector.

What I want to do is, every iteration of this loop, the values of the temp_vector is pushed back into the global 1D vector at the right position.

So for example:

std::vector<double> global; 
std::vector<double> actual = {1,1,0,0,2, 3, 4 ....., n};  

// here loop over n number of elements 

// TRANSFORM:
   // std::vector<double> temp_vector = {10, 50}; // after calculations 
   // global.push_back(temp_vector); 

So at the end result, the global_vector will still be a 1D vector, however, will contain all of the values, in the same place for each of the elements.

I hope I have explained myself enough!

Phorce
  • 4,424
  • 13
  • 57
  • 107
  • 1
    @user1326876 - this is up for a close vote. I think its a quality question, but its not clear what you are trying to accomplish. Could you provide examples? For example, show what you start with in `actual` with a small data set, describe the transform, and then show what `global` looks like at the end. – jww Jan 14 '14 at 03:11

2 Answers2

2

Here is code for array merging:

#include <vector>
#include <iostream>

int main() {
        std::vector<int> glob = {1, 2, 3};
        std::vector<int> temp_vector = {4, 5, 6};

        glob.insert(glob.end(), temp_vector.begin(), temp_vector.end());

        std::vector<int>::const_iterator it = glob.begin();
        for(; it != glob.end(); ++it) {
                std::cout << *it << ", ";
        }
        return 0;
}

Output:

./a.out
1, 2, 3, 4, 5, 6, 
vershov
  • 928
  • 4
  • 6
0

Consider to use an ordered container like std::set or std::priority_queue and insert into that container directly, not using a temporary.

Manu343726
  • 13,969
  • 4
  • 40
  • 75