Vectors are sequence containers representing arrays that can change in size.

learn more… | top users | synonyms

6
votes
3answers
502 views

STL Vector Implementation

I've implemented a simple vector like STL C++. ...
5
votes
3answers
170 views

Determine whether one vector is a prefix of the other

Exercise 5.17: Given two vectors of ints, write a program to determine whether one vector is a prefix of the other. For vectors of unequal length, ...
6
votes
3answers
203 views

Inner product of random floats written to file

My goals are to make this code: faster more idiomatic C++ What the code does: take an integer command-line argument N make a vector of ...
2
votes
1answer
52 views

Best way of assigning an array of different (but convertible) type to concurrency::array in C++AMP

I am creating a vector class which can be manipulated on the GPU and I am using C++AMP for the GPU accelerated code. I am wondering the most efficient way of assigning elements of a different type ...
4
votes
2answers
109 views

Optimizing object-returning functions in a Contours class [closed]

I have an class Contours that contains a vector of contours. I use OpenCV to store the contours, and I have another class ...
8
votes
3answers
250 views

Storing words from an input stream into a vector

I'm extremely new to C++ and am doing the exercises on the book Accelerated C++. Here is one of the exercises: 4-5. Write a function that reads words from an input stream and stores them in a ...
3
votes
3answers
123 views

Avoiding object slicing within abstractions and their derivations

I've created a rudimentary example of the issue I'm inquiring about: Object slicing. I followed a post on Stack Overflow which provided a similar template - and for all intents and purposes, this ...
8
votes
4answers
491 views

std::vector composition with self populating super-powers

I have written a deliberately pretty simple class that wraps a std::vector to basically make it capable of self-populate itself with random generated numbers, ...
3
votes
4answers
306 views

Creating a custom Vector class

I'm new to C++ and am doing the C++ 4th Edition Stroustrup book. I expanded on one of the examples, and have a few questions to ask (embedded within the code: ////QUESTION 1-9). Please provide any ...
2
votes
2answers
120 views

split string into container on char; efficiently?

Here is my single parse code for splitting a std::string on a char into a ...
3
votes
1answer
106 views

OpenMP loop parallel for loop with function calls and STL vector

I have a function initialize_path_statistics(). I have used openMP to make it parallel. I am not sure where certain lines such as ...
6
votes
2answers
180 views

Calculate Suitability Score program

I am a beginner in C++ and learning from textbook. I find it hard to jump into oops concepts as I have used C a lot. Here is an interview question I came across: Problem Statement Our ...
10
votes
2answers
236 views

Template vector struct in C11

This one review will be a little bit tricky: I was trying to implement a template Vector struct in C11. Of course, templates don't really exist in C11, so I used a ...
4
votes
2answers
173 views

Reimplementation of C++ vector

I previously attempted to make a C++ vector here, yet it was not very successful. Now I have made a basic reimplementation of it, so I'm checking that it is fine, and that I will not have to re make ...
10
votes
2answers
2k views

C++ vector implementation

I have tried to implement a basic vector type in C++, yet I am not sure if I can do anything any more efficiently. ...
3
votes
2answers
146 views

Optimizing a vector loop

Visual Studio somehow optimizes the below code to be 20 times faster (release with optimization vs. release with no optimization). What could it be doing? ...
3
votes
1answer
259 views

best way to write series of objects to a .ser file using ObjectOutputStream and read them back [closed]

I create series of objects out of Student Class and store them in a vector. I write each object in to a .ser file once it created. Then I read them back. My code is working perfectly. What I want to ...
4
votes
2answers
216 views

Merge two sorted arrays together

Please review my answer for this interview question: ...
2
votes
1answer
385 views

vector<tuple<A,B> > to map<A,B>

i have an vector<tuple<A,b> > v and want to make a map<A,B> from it i came up with 3 variants: ...
2
votes
3answers
2k views

Simple class exercise - min, max, and average of vector items

This program calculates the min and the max value and the average of the items of a vector. It's an exercise from a book so I can't change the header file. Is this code proper? sales.h ...
0
votes
0answers
68 views

Creating an updating hash table

I'm not sure if this implementation is good enough. The function takes a vector of 1 million chars and creates a table of the sequences that pass before the next occurrence of itself. Some questions ...
3
votes
2answers
265 views

Comma-formatted STL vectors

I move back and forth between Python and C++ and I often need a nice/quick way to output STL objects to the screen for debugging purposes. I'd like the output to match the output of a comparable ...
4
votes
2answers
163 views

Template vector class

I am trying to implement a vector-like container of my own (just to gain a better understanding of how std::vector works under the hood). I've been using this as a ...
4
votes
4answers
252 views

Reducing memory usage of nested vectors

I recently asked this question about performance of an unordered_map, but I realize my question is probably more about this piece of code here. I create a 8 x 10 x 30 x 30 x 24000 nested vectors of ...
6
votes
4answers
1k views

C++ vectors sort ascending/descending

How can I eliminate repetition from this code? ...
1
vote
1answer
94 views

Should I call a method (i.e. size()) multiple times or store it (if I know the value will not change) [closed]

I have a function that searches the shortest vector in a vector of vectors of pointers. Which is a better way? ...
5
votes
4answers
370 views

Given a number represented as an array of digits, plus one to the number

Given a number represented as an array of digits, plus one to the number. ...
4
votes
1answer
107 views

Reading contents of a file consisting of strings separated by a null character

This is my first attempt at reading the contents of a file consisting of strings separated by a null character. ...
4
votes
1answer
301 views

Vector implementation - simple replacement

This is intended to be a simpler replacement of std::vector, written for entertainment. It should be as fast or faster than ...
5
votes
1answer
313 views

A pointer vector sorted by its member function

I'm asking for suggestions on a random accessed vector with allocated elements sorted by its key obtained from its member function. I use it with Qt tree view where the access, add and deletion of ...
6
votes
1answer
482 views

Vector of derived classes

Everyone knows you can't put a Derived in an std::vector<Base>. I decided to implement a collection which does allow you ...
2
votes
2answers
385 views

Simple container class with templates

I've been working on a simple program to output values to the console as a learning project, and I stumbled across an article advising against using 2D containers, suggesting to simulate them instead ...
13
votes
8answers
20k views

Java function to read a CSV file

I have a java function that reads a csv and returns its content as a Vector<Vector<String>>. The function seems to work as I need it, but my gut ...
0
votes
1answer
240 views

remove continuous duplicate

i've made a little function for eliminate continuous duplicate from a std::vector. i have to use c++03! for example if a vector of int is composed of: 1,1,2,3,,3,1,1,2 my function shoul return ...
4
votes
1answer
294 views

Vectors assignations and operations in a loop and parallelization with OpenMP

I use this piece of code to compute a short-time Fourier transform: ...