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
2 answers
37 views

Implementing a function that takes in 2 collections of strings and compares them as if they are unordered in Rust

I'm new to Rust and I would like to implement a function to compare 2 collections of strings. The function should compare them as if they are unordered. In Python, I would implement something like ...
  • 13
0 votes
0 answers
78 views

Vector with small internal buffer

I implemented a vector with small inline storage to avoid allocation when the size is small. I am still new to Rust, so I have no idea how good this is. I tried to match ...
7 votes
6 answers
1k views

Compute "negative" version of vector of vectors

Given a std::vector<std::vector<double>> (e.g., representing some points in a space with D dimensions), I want to ...
3 votes
2 answers
95 views

C macro based dynamic array library

This library is a fork of eteran/c-vector. It is macro based, so that it is generic, without void pointers and additional functions. This of course means that it has the downsides of macros in C. The ...
2 votes
1 answer
89 views

C generic typesafe dynamic array (vector) try 2

The previous generic dynamic array I asked a review for here was written using only the preprocessor and so while the array itself was type-safe, all the manipulating macros where not. In this try I ...
2 votes
2 answers
75 views

Follow-up about computing lp norm with MPI

As pointed out in the answer by Victor Eijkhout to this question, the fact I am broadcasting the same vector to each process is against the MPI principles and, most importantly, will be a bottleneck ...
2 votes
1 answer
275 views

Compute lp-norm of a vector in parallel with MPI

I'm trying to solve the following exercise: Compute in parallel with MPI the lp norm of a vector of a predefined size N ...
2 votes
1 answer
74 views

Built a Vector2 class with easing functions, that can be unpacked

...
4 votes
1 answer
105 views

Growable vector on the stack with fixed capacity

Implements most (if not all) applicable member functions from std::vector and std::array Compatible with C++11, C++14, C++17, C++20 [] operator allows unchecked access, all other member functions ...
  • 43
0 votes
1 answer
45 views

Protein Translation Learning Exercise from exercism.org

I'm learning Rust by solving exercises from different tracks on Exercism. The below code is an implementation of "Protein Translation" from the Python track. I split ...
  • 435
1 vote
2 answers
56 views

Collect gaps in a number sequence in Rust using Vec::windows

I have the following code which collects gaps in a number sequence into a separate vec. There will never be a case, iterating over a ...
  • 201
1 vote
1 answer
68 views

General purpose 2D grid

I am developing (WIP) a mine sweeping game to get more familiar with Rust. I decided to represent the mine field as a 2D grid. While developing I realized that this grid can be outsourced as a general ...
1 vote
1 answer
244 views

Printing subarrays ⚡

I was trying to to print all subarrays of an array in quadratic time. Here is my code: ...
1 vote
1 answer
131 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
6 votes
0 answers
77 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
3 votes
1 answer
450 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
3 votes
1 answer
79 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
2 answers
521 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 ...
4 votes
2 answers
893 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. ...
2 votes
1 answer
78 views

Intersection of 2D vector equation straight lines

I know the vectors that describe two perpendicular 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 ...
1 vote
2 answers
58 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 ...
13 votes
4 answers
3k 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
0 votes
2 answers
668 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
4 votes
5 answers
2k 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: ...
5 votes
1 answer
197 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 ...
2 votes
2 answers
167 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 ...
  • 101
5 votes
2 answers
223 views

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

Here is the improved code ...
1 vote
1 answer
496 views

C++ vector bubble sort in my edition

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

Improving C++ Connect-four game with little AI

Here is the code for the game : ...
4 votes
4 answers
2k 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
4 votes
3 answers
957 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 ...
0 votes
0 answers
422 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 ...
2 votes
2 answers
422 views

Find neighbours of a vector

To find neighbors of a vector and return array of Vectors which are neighbors of a Vector: ...
  • 139
3 votes
1 answer
515 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 ...
  • 617
5 votes
2 answers
311 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 <...
4 votes
4 answers
994 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
0 answers
68 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,758
2 votes
1 answer
255 views

C - Generic vector library

I'm quite new to C, and I decided to create a generic vector library. Here is the code: ...
  • 289
1 vote
2 answers
474 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 ...
  • 413
6 votes
2 answers
329 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 ...
  • 63
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 ...
2 votes
1 answer
613 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 ...
0 votes
1 answer
72 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
3 votes
2 answers
119 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 ...
0 votes
1 answer
392 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 ...
4 votes
1 answer
112 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, ...
4 votes
1 answer
477 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 ...
5 votes
1 answer
69 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
1 answer
33 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, ...
  • 323
4 votes
1 answer
138 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 : ...

1
2 3 4 5
7