2022 Developer Survey is open! Take survey.

# 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.

299 questions
Filter by
Sorted by
Tagged with
1 vote
31 views

### Sort and search vectors by different criteria

Class class Player { std::string name; int score; int id; }; I thought about how to write a code to sort and search vector ...
• 11
56 views

### Chapter 8 Challenge: Add employee names to a department

The boring but exciting challenge: Using a HashMap and HashSet, create a text interface to allow a user to add employee names ...
• 61
439 views

### Which fruit fall onto my house?

I am following a question on a programming challenge website (here's the original reference). What I have is a house (start & endpoint) and some types of trees at their respective location points. ...
• 33
67 views

### C Typed Vector that implements type-safety, encapsulation and lazy initialization

C Typed Vector I wasn't happy with the various dynamic array / vector implementations in C, so I made my own. In general, I'm not the biggest fan of C-preprocessor madness, but alas for this ...
• 171
1 vote
188 views

### Table data structure in C++ using a vector of vectors

I'm learning C++, and now I have to implement a table data structure. I don't know a lot about C++, so I have implemented using a vector of vectors. To access the rows of the tables I have defined ...
• 253
668 views

### Custom implementation to provide an immutable range of a vector without copying it

Edit: A new and improved version can be found in this question, based on the feedback! I needed to pass a const reference to part of a std::vector without copy. ...
• 331
40 views

### Intersection of 2D vector equation straight lines

I know the vectors that describe two lines, $$\mathbf{a} + \lambda\mathbf{d}$$ and $$\mathbf{b} + \mu\mathbf{d'}$$ I've written a JavaScript function to get the coordinates of the point of ...
• 340
1 vote
41 views

### RE: Find maximum value of recursively-defined "fusc" function

Continued from the previous post - a brute-force approach to calculating all the vectors from 0 to n. I've come up with yet another solution, after I've realized that the vector takes up too much ...
2k views

### Vector Implementation in C

I made a somewhat simple vector implementation in C. Right now I only have around 5 features (making a vector, adding elements, removing elements, changing elements, deleting the vector). I'm proud of ...
• 471
215 views

### Separating odd numbers and even numbers into two vectors in C++

I'm learning C++, and would like some guidance. I'm pretty sure I'm doing something wrong. This algorithm runs in O(n) time and uses O(n) external space. Could I make a more efficient algorithm for ...
• 13
1k views

### C++11 Custom Vector Implementation

This was my solution to an interview question: Q: Implement an std::vector style container (does not have to be exactly compatible) with a fixed buffer and the following requirements and restrictions: ...
• 331
92 views

### Algo to return a vector of available time slots for scheduling a meeting between two persons

There are 2 persons and their already booked meeting schedule is given and also time bound for both the person is given. Now, we want to schedule a meeting between them in an available time that suits ...
108 views

### An implementation of Uber's “Fare Estimator”

CodeSignal put out a challenge by Uber that involves writing a "fare estimator" that involves a function dependent on cost per minute, cost per mile, ride time and ride distance. The formula ...
• 79
143 views

### C++ Connect-four game with little AI (Version two)

Here is the improved code ...
1 vote
353 views

### C++ vector bubble sort in my edition

I made a small adaptive function that sorts vector: ...
• 197
394 views

### Improving C++ Connect-four game with little AI

Here is the code for the game : ...
872 views

### Efficiently splitting a string in C++

I've made a splitString() function which receives a character and a string and returns a vector<string> containing all the ...
• 85
534 views

### Custom Vector Implementation in C++

I am relearning data structures while trying to implement them on my own while also trying to get better at C++ as although I have knowledge of C, OOP is still non-inituitive to me. In this simple ...
160 views

### Finding the Euclidean distance between the vectors of matrix a, and vector b

Here is the problem, Given a 2D numpy array 'a' of sizes n×m and a 1D numpy array 'b' of size m. You need to find the distance(Euclidean) of the 'b' vector from the rows of the 'a' matrix. Fill the ...
199 views

### Find neighbours of a vector

To find neighbors of a vector and return array of Vectors which are neighbors of a Vector: ...
• 139
182 views

### Inserting multiple elements at known locations in a vector

Goal In the vector x, I would like to insert the elements of the vector values at indices stored in vector ...
• 607
135 views

### Compressing a vector into a specific range

I want to solve the following task --- I am given a vector of integers. I want to 'compress' this list, where the elements will be replaced with numbers 0 through <...
• 153
941 views

### Given two vectors of ints, determine whether one vector is a prefix of the other

Given two vectors of ints, write a program to determine whether one vector is a prefix of the other. For vectors of unequal length, compare the number of elements of the smaller vector. For example, ...
• 209
1 vote
60 views

### A batch_recursive_count_if Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count_if Function For Various Type Arbitrary Nested Iterable Implementation in C++ and A recursive_count_if Function with Unwrap Level for Various Type ...
• 3,302
191 views

### C - Generic vector library

I'm quite new to C, and I decided to create a generic vector library. Here is the code: ...
• 269
1 vote
331 views

### C ArrayList implementation

I have written a ArrayList class in C and I just wanted some criticism on what I can improve on. Any criticism helps, and I was wondering if there is any better way of doing error handling other than ...
• 403
180 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 ...
• 73
1k 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 ...
258 views

### std::vector Allocator-Aware Implementation

I've just finally finished implementing std::vector. I'm currently re-implementing whatever I can in the hope to learn more of how data structures works. I tried to ...
68 views

### Find a sum using just two different digits

The problem statement was pretty easy and I was able to run half of the test cases, but some of the test cases in the end gave me the error of memory limit reached. What can I do here to improve the ...
• 13
106 views

### Implementing dynamic array without STL

For my game engine that I'm trying to write without using STL I implemented dynamic array class(some kind of std::vector). I would like to know whether this code suits best practices. I'm also not ...
• 33
276 views

### Vector Implementation C++ using RAII

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 ...
104 views

### C++ multi-threaded determination of curling numbers in vectors

for a thesis I am creating a program that constructs curling sequences. The curling number of a sequence is defined as 'the largest frequency of any period at the end of the sequence'. (For example, ...
393 views

### Implementation of the std::vector class

Looking forward to get your feedback on my attempt to replicate vector class functionality. Especially I have doubts about copy constructor and resize methods. I think that copy constructor could ...
66 views

### Handle (“potentially” occuring) scalar-Vector and Vector-Vector operations [closed]

I'm looking into fixing some obvious performance-related issues in my code but I tend to employ bug-introducing tricks as I do so. My code uses a library which defines ...
• 53
1 vote
29 views

### Cutting continuous variable into predefined blocks with custom labels

Background The function makes use of cut function offered in R's base package in order to "bin" a numeric vector into provided categories and apply, ...
• 241
39 views

### Seeking ideas for better efficiently deleting an element in a vector

While experimenting with some algorithm I decided to simulate it in R. I have a number of chronological elements in an array, and I want to prevent unlimited growth as new samples are added. So I ...
• 109
114 views

### C++ Dynamic Array Class Testing

I'm creating a basic Dynamic Array class in C++, and I'd like to know if there are any bugs/memory leaks I haven't noticed yet. dyn_arr.h : ...
88 views

### Find lowest consecutive value

I have created a program where I first set the size of the array and how many times I will look for consecutive values, then I fill in the array and finally I insert the consecutive values, it should ...
2k views

### Filtering a Vec of structs and creating new vector of Strings or strs in Rust

I'm working through the Rust book, and it has the following example of how to use the filter method on Iterators (source): ...
• 121
88 views

### Push_back algorithm for Vector

Hello everyone! I wrote a class Vector.So, I want to find out how can i upgrade it for better performance of my vector. Here is the code: ...
• 109
79 views

### Implementation of a vector of pairs

In a personal project I was working on, I had a vector of std::vector< std::pair<unsigned,char>>'s that represented a character and its position in the ...
• 39
170 views

### Large-scale pairwise similarity calculations of vectors

I am a C++ beginner and am working on a bit of code which calculates the pairwise cosine similarities between vectors. The vectors are TF-IDF vectors and the similarities are used to determine ...
• 23
37 views

### JDS - Cuda implementation

I am trying to implement the Jagged Diagonal Storage code in Cuda for Sparse Matrix - Vector multiplication. The code I wrote is as follows but I'm not sure about it: ...
• 121
130 views

### Linear Interpolation for sorted arrays

I have made a linear interpolation functions as a side project of mine. It assumes everything is sorted before hand - x and f(x) are the same length. I would like to ask for: general recommendations ...
420 views

### std::vector<bool> workaround in C++

I've been trying to make an std::vector of boolean values and I got fed up with the specialization. To get around this, I made a wrapper class around ...
• 1,705
3k views

### std::vector implementation C++

I just started studying data structures and being the std::vector the container that I most use in C++ I decide to try to implement it mimicking its behavior the ...
• 345
134 views

### dumb::vector - a class for students to use when they are expressly forbidden from using std::vector

I have created a small library for use by beginner C++ students who are forbidden from using std::vector in their projects. Because of this, I would like you to ...
• 368