Skip to main content
Share Your Experience: Take the 2024 Developer 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
0 votes
0 answers
35 views

Autocorrelation of a vector series (2)

Related: Autocorrelation of a vector series The given C# source code computes the autocorrelation of a vector series using a Fast Fourier Transform. Can you review this code for correctness? ...
user366312's user avatar
3 votes
1 answer
329 views

First dynamic array in C

I am new to C and have been learning it for about a month now. This is my attempt to implement a dynamic array. My code works, but i don't know whether or not it leaks memory. But my code works as I ...
Logeshwaran K's user avatar
1 vote
1 answer
98 views

Bit vector in Java supporting O(1) rank() and O(log n) select() - follow-up

(This post is the continuation of Bit vector in Java supporting O(1) rank() and O(log n) select(). It resides here (version 1.0.1).) Basically, I have implemented everything harold suggested, except ...
coderodde's user avatar
  • 28.4k
2 votes
3 answers
106 views

A dynamic array with an iterator compatible with std::sort

I wrote a Vector (dynamic array) class with an iterator usable with std::sort() . It seems to pass my tests. I wondering about the issues one can spot on this ...
KcFnMi's user avatar
  • 119
1 vote
1 answer
151 views

Bit vector in Java supporting O(1) rank() and O(log n) select()

Introduction I have this GitHub repository (version 1.0.0.). It implements a rank(i) operation in \$\Theta(1)\$ time, and ...
coderodde's user avatar
  • 28.4k
13 votes
5 answers
3k views

Dynamic array of int in C

This is my first C program I just wrote in like 30 minutes and I was wondering if you could give me any pointers on ways to improve this. I'm decent at programming (around 5 years experience), but ...
Zachiah's user avatar
  • 233
1 vote
1 answer
208 views

Positive Segments

I'm trying to solve the following question: You have an array A of size n, containing −1 or 1 only, and s segments (not necessarily different). Each segment is defined by 2 integers li and ri (1 ≤ li ...
driver's user avatar
  • 212
-2 votes
1 answer
55 views

Market Portfolio Binary Search Tree [closed]

I'm trying to solve the following problem here: First line of input contains the number of days D. The next d lines contains a character c and a number x. If c is B, then buy stock . If c is S, then ...
driver's user avatar
  • 212
4 votes
2 answers
581 views

O(nlogn) Lexicographically minimal rotation code but tle on this particular case

Based on a small suggestion here , this code tries to find lexicographically minimal rotation (question) by successively comparing two adjacent substrings in the very left , that can potentially give ...
Aryaman 's user avatar
4 votes
1 answer
161 views

C++ custom vector class implementation

I've developed a custom vector class in C++, complete with functionalities like assignment, push_back(), emplace_back(), pop_back(), clear(), and size(). I would greatly appreciate any feedback on ...
Jacob's user avatar
  • 131
8 votes
2 answers
368 views

C++ std::vector Implementation

Implementation of the vector class in C++ for learning purposes. Tried to implement interesting parts from the API shown on cppreference.com, but some elements like ...
jdav22's user avatar
  • 361
4 votes
1 answer
522 views

C23 Vector Macro Implementation

I'm trying to implement a simple type-generic Vector with macros using the newest features of C23. Looking for any advice about macro design and pitfalls because I generally avoid macros at all costs. ...
Biggs's user avatar
  • 143
1 vote
2 answers
61 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 ...
James's user avatar
  • 13
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 ...
Filippo Bistaffa's user avatar
3 votes
2 answers
384 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 ...
DuckHunterZx's user avatar
2 votes
1 answer
118 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 ...
Itai Nelken's user avatar
2 votes
2 answers
82 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 ...
bobinthebox's user avatar
2 votes
1 answer
363 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 ...
bobinthebox's user avatar
2 votes
1 answer
127 views

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

...
DracoDaine's user avatar
4 votes
1 answer
232 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 ...
AdamF's user avatar
  • 43
0 votes
1 answer
54 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 ...
Saurabh's user avatar
  • 435
1 vote
2 answers
151 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 ...
Kim's user avatar
  • 201
1 vote
1 answer
79 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 ...
Richard Neumann's user avatar
1 vote
1 answer
346 views

Printing subarrays ⚡

I was trying to to print all subarrays of an array in quadratic time. Here is my code: ...
Vaibhav Vishal Singh's user avatar
1 vote
1 answer
625 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 ...
MeoH's user avatar
  • 11
6 votes
0 answers
98 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 ...
lml's user avatar
  • 61
3 votes
1 answer
458 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. ...
Hiro 's user avatar
  • 33
3 votes
1 answer
87 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 ...
Julius's user avatar
  • 171
1 vote
2 answers
1k 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 ...
VansFannel's user avatar
4 votes
2 answers
1k 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. ...
Dávid Tóth's user avatar
2 votes
1 answer
278 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 ...
minseong's user avatar
  • 749
2 votes
3 answers
106 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
5k 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 ...
dareesome's user avatar
  • 471
0 votes
2 answers
1k 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 ...
Asher I's user avatar
  • 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: ...
Dávid Tóth's user avatar
4 votes
1 answer
329 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 ...
Lame Things's user avatar
2 votes
2 answers
187 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 ...
Aleksey's user avatar
  • 173
5 votes
2 answers
248 views

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

Here is the improved code ...
Ahmed Elsayed's user avatar
1 vote
1 answer
784 views

C++ vector bubble sort in my edition

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

Improving C++ Connect-four game with little AI

Here is the code for the game : ...
Ahmed Elsayed's user avatar
4 votes
4 answers
9k 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 ...
And9686's user avatar
  • 85
4 votes
3 answers
2k 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 ...
slimmsady's user avatar
0 votes
0 answers
788 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 ...
Levon Avetisyan's user avatar
2 votes
2 answers
665 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
3 votes
1 answer
944 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 ...
Remi.b's user avatar
  • 617
5 votes
2 answers
546 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 <...
Mike Smith's user avatar
4 votes
4 answers
1k 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, ...
Natalo77's user avatar
  • 209
1 vote
0 answers
69 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 ...
JimmyHu's user avatar
  • 4,958
2 votes
1 answer
425 views

C - Generic vector library

I'm quite new to C, and I decided to create a generic vector library. Here is the code: ...
xilpex's user avatar
  • 289
1 vote
2 answers
625 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 ...
CLox's user avatar
  • 419

1
2 3 4 5
7