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.

Filter by
Sorted by
Tagged with
1 vote
1 answer
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 ...
user avatar
  • 11
6 votes
0 answers
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 ...
user avatar
  • 61
3 votes
1 answer
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. ...
user avatar
  • 33
3 votes
1 answer
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 ...
user avatar
  • 171
1 vote
2 answers
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 ...
user avatar
4 votes
2 answers
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. ...
user avatar
2 votes
1 answer
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 ...
user avatar
1 vote
2 answers
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 ...
user avatar
13 votes
4 answers
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 ...
user avatar
  • 471
0 votes
2 answers
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 ...
user avatar
  • 13
4 votes
5 answers
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: ...
user avatar
5 votes
1 answer
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 ...
user avatar
2 votes
2 answers
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 ...
user avatar
  • 79
5 votes
2 answers
143 views

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

Here is the improved code ...
user avatar
1 vote
1 answer
353 views

C++ vector bubble sort in my edition

I made a small adaptive function that sorts vector: ...
user avatar
  • 197
6 votes
2 answers
394 views

Improving C++ Connect-four game with little AI

Here is the code for the game : ...
user avatar
4 votes
4 answers
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 ...
user avatar
  • 85
4 votes
3 answers
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 ...
user avatar
0 votes
0 answers
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 ...
user avatar
2 votes
2 answers
199 views

Find neighbours of a vector

To find neighbors of a vector and return array of Vectors which are neighbors of a Vector: ...
user avatar
  • 139
2 votes
1 answer
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 ...
user avatar
  • 607
5 votes
2 answers
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 <...
user avatar
4 votes
4 answers
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, ...
user avatar
  • 209
1 vote
0 answers
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 ...
user avatar
  • 3,302
2 votes
1 answer
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: ...
user avatar
  • 269
1 vote
2 answers
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 ...
user avatar
  • 403
7 votes
2 answers
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 ...
user avatar
  • 73
8 votes
3 answers
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 ...
user avatar
2 votes
1 answer
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 ...
user avatar
0 votes
1 answer
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 ...
user avatar
  • 13
3 votes
2 answers
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 ...
user avatar
0 votes
1 answer
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 ...
user avatar
4 votes
1 answer
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, ...
user avatar
4 votes
1 answer
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 ...
user avatar
5 votes
1 answer
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 ...
user avatar
  • 53
1 vote
1 answer
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, ...
user avatar
  • 241
0 votes
0 answers
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 ...
user avatar
  • 109
4 votes
1 answer
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 : ...
user avatar
3 votes
1 answer
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 ...
user avatar
2 votes
1 answer
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): ...
user avatar
  • 121
-1 votes
1 answer
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: ...
user avatar
  • 109
0 votes
1 answer
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 ...
user avatar
  • 39
2 votes
1 answer
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 ...
user avatar
  • 23
2 votes
0 answers
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: ...
user avatar
  • 121
3 votes
1 answer
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 ...
user avatar
7 votes
2 answers
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 ...
user avatar
  • 1,705
3 votes
4 answers
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 ...
user avatar
  • 345
2 votes
1 answer
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 ...
user avatar
3 votes
2 answers
120 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: ...
user avatar
9 votes
2 answers
696 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 ...
user avatar
  • 354

1
2 3 4 5 6