# Questions tagged [vectors]

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

283 questions
Filter by
Sorted by
Tagged with
5k views

### C++ Vector Clone

I'm learning C++, so I decided to make a simpler clone of std::vector. Concerns: I have seen people defining methods outside of the class, and only prototyping ...
81k 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. ...
50k 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 ...
606 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 ...
289 views

### YAVI (Yet another vector implementation)

I am a C# game developer currently learning C++. I am trying to implement some simplified STL containers. Here is my implementation of vector, which does not have the allocator (because ...
36k views

### C++ Split string into a vector

While profiling parts of my code, I noticed that my Split( ... ) function is rather slow, (about 50% of the time). I was wondering if there was a more efficient way ...
4k 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 ...
11k views

### Basic iterator supporting vector implementation

On the fly, I just implemented this iterator supporting vector class to understand how range-based for loop works. It's really basic but let me know what can be improved. Vector.h ...
2k 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 ...
6k views

### Modern Vector implementation

Please give me some feedback on my attempt at a vector. I wanted this to be the lowest level concept of a vector that I'm using, so I'm primarily concerned with speed, and I would build wrappers ...
8k views

### A vector implementation

I am an undergraduate currently learning data structures and C++. I am trying to implement some simplified STL containers. Here is my implementation of vector, which does not have the allocator. My ...
8k 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. ...
2k views

### Implementation of a generic List

I have only been self teaching myself programming on and off for about 5 months. The purpose of me writing this class is to incorporate the knowledge that I have gathered since I started. ...
338 views

### Dynamic vector of void* in C

I have implemented a simple dynamic vector library in C. It is a header-only library. Full library listing - void_vector.h: ...
2k views

### A simple program with trains and inheritance

Here it is my program. I'm especially worried about the main because I know that one must be careful while instancing vectors of "inherited" objects. The code I have works fine (as far as I can see) ...
2k views

### Simple re-implementation of std::vector

Here is a simple reimplementation of most of std::vector. I want to check if I implement it correctly but the standard libraries source code is not very readable ...
394 views

I've just finished a homework assignment to implement a simple Vector class. -Kindly ignore the following two paragraphs if you don't want to read someone whining about their professor Yadda, yadda, ...
5k views

I need to read a range of bytes from a file and return it as a std::vector<std::byte>. My current code looks like this: ...
7k 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 ...
1k 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 ...
127 views

### IndexedVector - holding a vector of unique objects with faster finding elements

I am trying to write a class that will enable me to hold an std::vector of some unique objects, but faster finding elements already stored in a vector. I want the ...
12k 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 ...
338 views

### C++20 standard compatible vector

I decided to write my own vector class template for learning purposes. My main goal was a correct interpretation of C++20 standard (as of n4810). I took some liberties and decided to use concepts ...
4k views

### Implement Own Vector Class in C++

I am preparing for an interview and came to know about this question: implement a vector class in C++. I thought of how I would write it an interview and included the code below. The things I know I ...
425 views

### Proper Case Conversion (Performance)

I wrote a simple function that converts an array of words into proper case (using bitwise operations) and returns the array. I performed a simple test using ...
3k views

### Removing by indices several elements from a vector

From a sorted vector of indices (toRemove), I would like to remove from another vector (v) the elements at these indices. Note ...
8k 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 ...
639 views

### 0/1 knapsack algorithm implementation with possibilities vector

The following code uses dynamic approach to solve 0/1 knapsack problem. (I know the maximum profit function I have used is not as good as the one I have defined ...
215 views

### Generic data structures in C

I'm new to C, and I thought a great way to learn would be to implement some generic data structures and algorithms. So far I've implemented a linked list and a dynamic array. Both are generic, the ...
2k views

### Most efficient way to find an entry in a C++ vector

I'm trying to construct an output table containing 80 rows of table status, that could be EMPTY or USED as below ...
930 views

### C++ Creating custom vector

I am new to C++ and Data structures, so I have started writing a custom vector as a practice. Please provide critique and advice. I know it is quite long, so thank you very much in advance. I just ...
1k views

### Reverse each word in the string. All spaces in the string should be retained

This was part of a code challenge. I use them to help me learn c++/c# along with tutorials and guides. Basically I was taking a string... The quick brown fox jumps over the lazy dog. ...and ...
2k 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 ...
1k views

### Counting pairs of integers whose sum is less than a given threshold

Recently I was going through this codechef problem while practicing for the upcoming zoc. The problem asks to calculate number of combinations of the given numbers where the sum is less than another ...
1k 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, ...
336 views

### An alternative vector

Based on this question (as a starting point) and a couple of other questions about rewriting vector in C++, I am planning to write another blog article to show the best way (or more precisely, the ...
1k views

### C++11 Vector with move semantics

I am practicing move semantics and placement new by writing a custom Vector class but I am not confident that I use them right. I would really appreciate some pieces of advice regarding my code. Here ...
10k views

### C++ vectors sort ascending/descending

How can I eliminate repetition from this code? ...
2k views

### Pascal's triangle using C++ vectors

This is my C++ program. I wanted to print out Pascal's triangle. I let the user decide how many rows to print out. The first row is considered as 0, and is just: 1 I'm using vectors for this task. ...
135 views

### re-implementation of std::vector

I've implemented a simple vector-like structure. I would appreciate all criticism relevant to code. I have also published code under github. Here is the link to source code + unit test for most ...
64 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 ...
314 views

### Graphical editor programming challenge

I have posted here my working and accepted solution to the graphical editor programming challenge (detailed here) for your review. The program recognizes the following image editing commands: ...
200 views

### An Alternative Vector (Copy Assignment Operator)

This is a continuation of 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 ...
2k 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 ...
3k views

### Vector-transposing function

I profiled a library I'm writing that uses vector transposes and found that I am spending a good bit of time doing the following transpose. I am using a std::vector ...
2k 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 ...
7k views

### C++ Template-Based ArrayList Implementation

As part of my learning C++, I have created an ArrayList class. It shares some of its interface with the Java ArrayList, but it by no means implements anywhere close to the full set of functions an ...
1k views

### Sort Characters By Frequency

I solved this problem. Problem Statement Given a string, sort it in decreasing order based on the frequency of characters. Example 1 Input: "tree" Output: "eert" ...