# 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
31 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 ...
19 views

### vector out of range exception in my code [closed]

I am writing a C++ code for some Monte Carlo simulations. In the simulations, I am storing matrices and updating them based on some rules. So to do this, I created two classes : a 5D matrix class, and ...
95 views

### Find neighbours of a vector

To find neighbors of a vector and return array of Vectors which are neighbors of a Vector: ...
50 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 ...
89 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 <...
914 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, ...
1k 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 ...
29 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 ...
70 views

### C - Generic vector library

I'm quite new to C, and I decided to create a generic vector library. Here is the code: ...
10 views

### Extracting integers from arbitrary text and storing them in a dynamic array

Minimal vector-like dynamic arrays, min_array.h. This is not new at all, but since I use a lot of functions similar to this in larger projects, I was hoping for ...
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 ...
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 ...
60 views

### Delete the node at index i from its current position and insert it after node at index j

I was trying to create a function to delete the node at index i from its current position and insert it after node at index j ...
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 ...
106 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 ...
66 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 ...
101 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 ...
82 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 ...
97 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 ...
95 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, ...
347 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 ...
60 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 ...
2k 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: ...
28 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, ...
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 ...
78 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 : ...
82 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 ...
378 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): ...
75 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: ...
53 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 ...
73 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 ...
24 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: ...
76 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 ...
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 ...
146 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 ...
1k 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 ...
112 views

### Implementation of a Smart To-do List Algorithm

This is a small program to implement the FVP algorithm (outlined here). I'm still quite new to C++ and don't have a strong grasp of basically any concepts. Concepts I tried to use in this program: ...
103 views

### What changes should I implement in my templated sorter class so that it performs efficiently?

I have a college assignment to implement a class called sorter, whose object is a sorted vector (the user is allowed to sort it by the method he/she desires). I have been able to implement it as ...
227 views

### A job sequencing solution

I have written this code as a college assignment fot the famous job sequencing problem. Please tell me any improvements if possible. Oh, for algorithms.h header ...
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 ...
171 views

### Finding median of sub arrays taking too much time

I'm trying to solve a programming challenge where I have to find the median of given subarrays of an array. I have used std::vector's ...
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 ...
129 views

### Dynamic array class in c++

So, as an exercise I wanted to write a dynamic array, like std::vector. I wanted to know if there are any things that could be done better or anything I did wrong. Thank you! ...
241 views

### Sorting multiple vectors based on a reference vector

I am trying to sort vectors based on a reference vector. First I am getting the indexes for the reference vector and then using that I am doing inplace sorting for the rest of the vectors. ...
3k views

### C++ Heap implementation

I'm on my way of understanding basic data structures and sorting algorithms through implementing them in c++. Post is followed of my implementation of Vector. I decided to weld the heap behaviour ...
108 views

### A simple 3D Wrapper class around std::vector

I am working on a very simple 3D vector class, which I can use to set up and access three-dimensional vectors using a wrapper around std::vector. It's not intended to be foolproof, just good enough to ...
97 views

### Pointers to polymorphic classes saved in vector that reference data in a list as source

I have a list called data with strings in it. I have a class String that derives from class Item. A class ...
83 views

### Bin Numbers from stdin

I often like to get a feel for a text file containing a lot of numbers quickly by making a histogram. One can do this in plotting software like Gnuplot, but sometimes having something in the terminal ...