Questions tagged [push-back]

is the action of adding an element at the end of a container.

push-back is the action of adding an element at the end of a container.

420 questions
0
votes
2 answers

Is random access and push_back without invalidating the elements possible in C++?

Basically I need to be able to use operations like push_back() + random access a list like std::vector is able to do, while also keeping its pointer validity, like std::list does. Is this possible? I was working with pointers pointing to various…
Ramster445
  • 45
  • 5
0
votes
2 answers

why is my rudimentary implementation of Vector faster than the stl version for push_back?

I have implemented a rudimentary vector using the code from the Weiss C++ textbook on data structures (see below). when i time it with 100,000 push_backs it takes 0.001 seconds. when i do the exact same experiment using the stl::vector, it takes…
Russell Butler
  • 326
  • 4
  • 15
0
votes
1 answer

Is std::string::push_back faster than std::string::append?

I usually use the += operator to add content to an std::string which is seemingly the same as std::string::append. There is also the push_back method for a string which allows to add one character at a time. For now, I always use += since it is…
Kaiyakha
  • 1,463
  • 1
  • 6
  • 19
0
votes
0 answers

Is there a way for adding multiple n elements to end of vector in O(1) complexity for C++17

I have try to develop an algorithm and in some times i should add multiple elements of a vector to another vector's end. Is there a way to proceed this in a constant time? Also, is there a way for another data structures(such as arrays and…
0
votes
1 answer

Time Complexity push_back C++

I'm wondering if we have a matrix declared as vector> matrix and we want to push back to the matrix another vector let's say vector array = {1, 2, 3}, what would be the time complexity of matrix.push_back(array)? My guess would be…
0
votes
0 answers

vector.push_back() improving performance

Is there any way to improve the performance of this function? As I have to call it ~10-100M times for 1 calculation it's slowing down my program and most time has been lost in this line: myHand_param.FinalHandVector.push_back((1 <<…
0
votes
0 answers

How do we solve to std_vector>::_M_realloc_insert() crash?

first:std_vector.h 948行: push_back函数插入崩溃 second:new_allocator.h 111行:std_vector>::_M_realloc_insert(__gnu_cxx::normal_iterator>>,float const&) result:std_vector>::_M_realloc_insert() crash please all friends give some advinces
0
votes
1 answer

Why is the member value of parent lost in the vector after push_back()? (C++)

I would like to push an instance of Child (Parent is the base class of Child), in a vector using push_back(). But then the value of the Parent members lost. In the following example, I would like to see 70 when writing the vector to the console, but…
fanstr
  • 3
  • 1
0
votes
4 answers

String appending integers from a vector of int won't print anything

Background: I just finished an exercise that involved making a stack using linked lists, and then using a vector of char stack to perform various functions such as converting decimal numbers to binary, hexadecimal, and octal, and reversing a string.…
F.A.
  • 15
  • 5
0
votes
0 answers

Storing in a vector based on certain criteria

Good morning Stack Overflow, I am having trouble getting some key-value pairs to store in a vector only if they meet certain criteria which I will explain below. Everything is working in my program so far except this. To begin here is my main: int…
krainey916
  • 17
  • 5
0
votes
3 answers

Adding elements to C++ vector

I want to learn more about C++ coding, especially to design and create a desktop application. To begin, I want to create a notification app where I can make a task by giving the task a name and content. For this, I use 2 vectors (name and…
0
votes
1 answer

Is using the overloading << operator as push_back a good idea?

I've been practicing with operator overloading in order to comprehend it better and I came across using the << operator with vectors like this: void operator<<(std::vector &vector, int value){ vetor.push_back(value); } Now I know that this…
Isaias
  • 43
  • 1
  • 5
0
votes
1 answer

Stl container vector push_back with OpenMP multithreading

I want to push_back an object into a vector from different threads. The no. of threads depends on the machine. #pragma omp parallel shared(Spaces, LookUpTable) private(LutDistribution, tid) { tid = omp_get_thread_num(); …
Florian
  • 1
  • 1
  • 1
0
votes
2 answers

Vector parameter in a function doesn't seem to actually apply to input?

I have a vector variable named intVec, and I have a function named pushBack, that accepts a vector of type integer just like intVec, but when I actually pass that vector into the function in order to push_back the x parameter, nothing seems to…
101123
  • 3
  • 1
0
votes
2 answers

Vector push_back() and direct assignment using [] give different results

I'm trying to do this nQueens problem and my code looks like this: class Solution { public: vector> ans; bool canPlace(vector &board, int row, int col, int n){ //upper left diagonal int rowIndex =…
MaySha
  • 20
  • 1
  • 4