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

learn more… | top users | synonyms

0
votes
0answers
21 views

Two ways to use objects/ vectors [on hold]

I would like to do this with the first example, would doing so be more intensive than the second way? used in both examples ...
11
votes
2answers
117 views

How to speak Brainfuck: for beginners

The following code transforms multi-line input into the the Brainfuck equivalent. One line turns into one program. The resulting programs are split by newlines for readability. Brainf.cpp ...
2
votes
1answer
56 views

Passing functors to standard algorithms

I created 3 different implementations (which produce the same results) using the count_if function from STL. I wish to check the number of elements in the vector ...
2
votes
1answer
96 views

Second implementation of std::vector

Having already attempted an implementation of the std::vector class here, I decided to take the comments on board and also do some new bits myself (mainly the ...
3
votes
2answers
71 views

Fastest way to search istringstream for patterns in around 0.02 seconds

Problem I have a stream composed of 2 columns and 1000 lines: Column 1: contains the patterns that I want to find Column 2: contains the values corresponding the the patterns in Column1 I want to ...
5
votes
1answer
105 views

Implementation of std::vector class

I decided to implement the std::vector class in C++, and was wondering if I had done everything correctly. When I mean 'correctly', I mean that the code is ...
4
votes
3answers
72 views

`std::vector` 'substring concatenator'

The point of this is to concatenate a vector of std::strings into one string starting at an index of the vector. ...
2
votes
0answers
48 views

Serialize/deserialize a vector using insertion/extraction operators

I've never serialized a structure to a file before in C++, so I'm looking for critique on my first try at it. My main concerns are: It uses the streams space-delimited behavior. If a ...
4
votes
1answer
95 views

Self Implemented Hash Map Performance

I have written two hash map implementations, one that stores Vertices and one that stores self implemented vectors of Edges. They are all fully functioning, however in my application they are quite ...
3
votes
1answer
73 views

Calculating the determinant of a matrix

I wanted to do some exercise and came up with the idea of a good challenge (for my level of course). I tried to implement Laplace's algorithm for computing the determinant, recursively. ...
4
votes
1answer
71 views

Maximum sum subarray efficiency — divide and conquer w/ vectors

I have successfully implemented a divide and conquer approach for find the maximum sum subarray (see code below). The code works fine and is correct, however I have an efficiency problem in that in ...
2
votes
2answers
113 views

Using std::vectors to store textures

I need to write a TextureManager class which stores Texture objects; the problem is I'm using an ...
2
votes
1answer
54 views

Printing a multilevel container

I have these struct(s) to keep data about temperature measurement: ...
3
votes
1answer
140 views

Selecting variable amount of vector elements in C++

Suppose we are given a C++ vector. We want to specify a variable amount of indices and select elements from a vector being indexed. I have two implementation: (A) one relies on C++11 initializer ...
3
votes
0answers
78 views

C++ vector implementation errors

I haven't really programmed in C++ for about a year, and realised that I should get back into it, and tried my abilities out by remaking the STD vector class. However, my C++ is a bit rusty at the ...
1
vote
2answers
200 views

Defining std::vector::push_back(new Object)

Is this the best way to construct a vector of 2D points for return? I don't entirely understand new and delete so I'm concerned ...
7
votes
1answer
43 views

Managing initialization for a vector abstract data type in C

As an assignment, I was to create an \$n\$-dimensional vector type for \$n \le 20\$. This vector only has to support addition and scalar multiplication. I tried to write good code, with proper memory ...
4
votes
1answer
81 views

Vector implementation

This is a C++ Vector that I've made for the pleasure of it. It was made on a whim and is not related any school assignment or anything alike this. This Vector does ...
6
votes
2answers
338 views

Longest string in a vector — two implementations

I was given this piece of code, which calculates the length of the longest string in a vector of ...
3
votes
2answers
237 views

Wrapper function to do polynomial fits with gsl

I have two arrays of double, say x and y containing some physical data. I would like to find ...
2
votes
2answers
142 views

Basic myVector class raw vs smart pointer

I'm writing a myVector class for a class I'm taking. I don't believe I'm "strong" with smart pointers right now, so that's my question. This is just an excerpt ...
5
votes
1answer
147 views

Random interval generator for a game

I have been working on a few games which all have a need to create "events" randomly over time. The intervals need to get shorter as time goes on if the event is negative or they need to get longer ...
6
votes
2answers
107 views

Vector backed by memory pages

The purpose of this class is to wrap a std::vector in a class so that never a new object is added. We don't allocate a new object on the stack but we trying to fit ...
4
votes
1answer
723 views

Filling a container with objects using pointers / iterators

I have a series of nested objects that I need to serialize into a byte (unsigned char) array to send out to another computer over UDP. Right now I each object ...
1
vote
2answers
134 views

Speeding up and shortening a loop [closed]

I'm still relatively new to C++ and I've written a program that could do with being a bit shorter and faster. I use this same set of for loops many times to cycle through the whole tree of values. ...
3
votes
2answers
1k views

Read binary file by blocks

I wrote a function that allow me to read a binary file using 3 blocks what ever the length of file. I've decided to divide the length of my file into 3: block 1: ______________ block 2: ...
-1
votes
2answers
101 views

LinkedVector : a vector of elements with links to other elements

I wanted to have a vector with usual values and with some sort of indexing : an element can have links to other elements (via indices). Something like the following, where ...
7
votes
2answers
466 views

Sorted vector (aka flat_set) for objects (pointers) with custom embedded key (functor used)

BEFORE YOU READ: this link should be included when you just don't like the format of the question and for those that read this question for the first time, the link may give you the idea what happened ...
2
votes
2answers
78 views

Optimizing a particle filter weighted selection step

I have a vector with 10000 particles that I use in a Particle Filter. The problem is that it's taking too long to compute the weighted selection of the particles. I want to use a vector of weights ...
7
votes
3answers
9k views

STL vector implementation

I've implemented a simple vector-like structure. I would appreciate all criticism relevant to code, style, flow, camelCase vs underscore, and so forth. ...
5
votes
3answers
244 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
263 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 ...
8
votes
3answers
2k 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 ...
4
votes
3answers
518 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
704 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, ...
4
votes
4answers
5k 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
807 views

split string into container on char; efficiently?

Here is my single parse code for splitting a std::string on a char into a ...
4
votes
2answers
384 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 ...
5
votes
2answers
264 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 ...
12
votes
2answers
553 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
282 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
5k 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
289 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
551 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
697 views

Merge two sorted arrays together

Please review my answer for this interview question: ...
2
votes
1answer
909 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
4answers
6k 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 ...
1
vote
0answers
89 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
408 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 ...