Vectors are sequence containers representing arrays that can change in size. For questions about geometric or algebraic vectors, use [coordinate-system] instead.

learn more… | top users | synonyms

3
votes
3answers
50 views

Place integers into a vector, sum each adjacent pair, refill vector with only the sums of each pair i.e remove all the original data from the vector

Is there a quicker/better way of doing this, mine works great for small vectors but if i get a vector with an arbitrarily large size this would probably take forever to run. Thanks.(P.S. its been a ...
6
votes
5answers
671 views

An ordered set in C#

I need a generic data structure that ensures that its elements are unique. C# has HashSet<T>, great! As it turns out, the elements have to stay in the order ...
2
votes
1answer
80 views

Auto-resizing array, that accepts negative indexes

I've been coding a helper container template to contain tiles in 2D games. What I figured out I would like when writing code for my games is forgetting all resize stuff, allowing negative indexes (for ...
2
votes
1answer
62 views

std::vector with custom growth factor

So, yes, I know that "you shouldn't derive from std containers" but by now it's more of philosophical rule in my mind than a technical one. I've googled again for the one fundamental reason one should ...
5
votes
4answers
826 views

Find all instances of element in array

I've created a function to return all the indices where an element is to be found in an array. If it occurs twice or more, all the respective indices will be returned, for now it returns them in ...
4
votes
2answers
57 views

Print max no of recent duplicate words

I am new to C++, learning from the book primer C++ The exercise: Write a program to read strings from standard input looking for duplicated words. The program should find places in the input ...
1
vote
1answer
60 views

Program to count number of victories in a pool of contests

I changed the program to use a dynamic array instead of a vector or storing the integers. This program works without bugs and executes relatively fast. The only doubt Istill have is how to fill the ...
3
votes
2answers
72 views

Filtering numeric vectors by proximity to any elements of another vector in R

I frequently want to filter and select elements from a long (10,000s to millions of elements) vector in R. Often, this vector is a column in a data.frame. I am ...
10
votes
3answers
270 views

C++ Vector The basics

Following on from my two previous posts. An alternative vector An Alternative Vector (Copy Assignment Operator) I have written a detailed blog about how to write a minimal vector like class. This ...
4
votes
0answers
78 views

An Alternative Vector (Copy Assignment Operator)

Continuing from the An Alternative Vector Taking a closer look at the copy assignment operator. In the following code I am only posting the new version of the copy assignment operator all the rest of ...
6
votes
4answers
157 views

An alternative vector

Based on this question (as a starting point) and a couple of other questions about re-writting vector in C++ I am planning to write another blog article to show the best way (or more precisely the ...
3
votes
2answers
67 views

Simple class for 2D <-> 1D array index conversion

I made a class to convert the index between 2D and 1D arrays. For example, between {1,3,5,7,9,11} and {{1,3},{5,7},{9,11}} When i is 0, ...
3
votes
1answer
79 views

Redirecting arriving customers to the nearest empty queue

I have a task to make a checkout line controller. First it receives, as input, an amount of checkouts and commands. Then commands that are C for coming and L for leaving, and after those the number of ...
1
vote
3answers
152 views

Performing operations on a processed int vector

This question came from C++ Primer 5th edition: Q: Read a set of integers into a vector. Print the sum of each pair of adjacent elements. Change your program so that it prints the sum of the ...
2
votes
1answer
85 views

Process string vector and change each string to uppercase

The question below came from C++ primer 5th edition. Read a sequence of words from cin and store the values a vector. After you’ve read all the words, process ...
2
votes
1answer
63 views

Matrix column switching

I'm currently working in the math library for a game framework that I'm writing and am working to improve some functionality that was affected during a refactor. Formerly, my ...
4
votes
2answers
64 views

Vector Sort Function

I had heard about sorting for a while, but never actually gave it a try. So I decided to make an algorithm that would sort the members of a vector from least to greatest. Though this may seem pretty ...
7
votes
1answer
146 views

Comparing std::vector<bool> to std::vector<char>

A recent comment to an answer of mine here on Code Review brought up an interesting point. The comment was that one should use std::vector<char> over ...
8
votes
2answers
246 views

Vector Implementation C++

I have attempted to implement a similar version of the STL Vector; several functions are missing but I'd like a few words of advice on whether I am indeed on the right track or whether I should change ...
5
votes
2answers
103 views

Counting inversions in C++ via mergesort and vectors [closed]

I have a text file that contains 100,000 numbers from 1 ~ 100,000 in an unsorted manner (no duplicates). The name of the file is "IntegerArray.txt" My task is to count the number of inversions in ...
5
votes
2answers
126 views

Multiplayer BlackJack using Vector

This is a small program I wrote for GCSE computing, it operates using Vectors and that's pretty much it, wondering if you could tell me if there is anything I could do better. BlackJackv2.cpp ...
7
votes
4answers
1k views

Custom vector that uses less memory than std::vector

I'm using vectors to create matrix and the vector itself is consuming a large space. So I implemented a version that would use less memory and, if possible, be as fast or faster than ...
4
votes
2answers
472 views

Mean, Median and Mode of a QVector

I would like some help condensing this code down to size. I am trying to utilize Qt's container classes as efficiently as possible. I do not believe this code reflects my objective. ...
3
votes
2answers
52 views

Convert hex encoded string to byte array

The following should read a hex string such as "ece998a2fb" into vector 236 233 152 162 251. I was unable to find any built in ...
3
votes
1answer
224 views

Divide and Conquer algorithm for counting inversions

I've written a program that counts the number of inversions using a Divide and Conquer algorithm, written in C++11. ...
0
votes
2answers
147 views

Implementation of Vector in C++

This is a simple implementation of vector in C++. Please offer your reviews to improve the code. ...
3
votes
2answers
301 views

Creating n-dimensional mathematical vector classes through inheritance

Right now I have no knowledge of templates, but I just finished learning about inheritance, and wanted to apply it to a Vector3 class that I had already created. My ...
0
votes
0answers
62 views

Flattening lists of Vectors and Matrices into arrays

For many optimisation methods the parameters must be given as a single vector, such as Optim.jl. But for many interesting functions the parameters/coeffients to be optimised are matrices, or a mixture ...
2
votes
0answers
30 views

Constant-space n-dimensional loops using dependent vectors

I designed this file after learning from this awesome answer from user2407038 on Stack Overflow. The idea of the module is to replace code like: ...
3
votes
3answers
93 views

Populating a vector with alternating numbers

This code inserts the number 4 into a vector's even indexes. ...
4
votes
1answer
131 views

Generic vector implementation in C using macros

I while ago I experimented with macros in C and came up with the idea of implementing a generic vector library using macros. This code uses the non standard typeof ...
4
votes
3answers
202 views

Writing huge 2D vectors to text file too slow

I have 10 large (34 million cell) 2D gridded vectors storing doubles. When written they are over 200 MB in size. I use an ofstream object to write them to a text ...
16
votes
2answers
329 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
142 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
146 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
84 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
180 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
151 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
86 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
167 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
1k 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
429 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
398 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
69 views

Printing a multilevel container

I have these struct(s) to keep data about temperature measurement: ...
3
votes
1answer
340 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 lists,...
3
votes
0answers
128 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
920 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
54 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
150 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 ...
7
votes
2answers
1k 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 ...