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
2answers
44 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! ...
2
votes
2answers
78 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. ...
5
votes
1answer
63 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 ...
2
votes
2answers
76 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 ...
-2
votes
1answer
56 views

Writing array to vector slows down program after each iteration [closed]

I have a C++ program where the input are 2 arrays, each containing a and z number of elements. The program then creates all ...
9
votes
2answers
407 views

Proper Case Conversion (Performance)

I wrote a simple function that converts an array of words into proper case (using bitwise operations) and returns the array. I performed a simple test using ...
3
votes
0answers
63 views

Program to output Low and High pass filter impulse response coefficients for signal processing

My issue that I was trying to solve was constructing a vector where the values were mirrored around the central element. The problem is here: https://stackoverflow.com/questions/58876916/construct-...
2
votes
0answers
38 views

Using python to estimate the range of unstructured data

I have unstructured input-output data, f=f(x). I want to estimate the range of f as a function of x, given limited sampled. So, I tried to discretize the data use small bins in x to estimate the ...
2
votes
2answers
67 views

Operator overloading in C++ to manage playlists of music

I've built this little C++ program just to take some rust off my coding skills since it's been ages since the last time I coded something. The purpose is to organize my music, so I've built the ...
2
votes
1answer
49 views

Find all palindromes in the danish language

I made a program to attempt to find all palindromes in the danish language. Words.txt contains about 50.000 lines of danish words. Palindromes.txt is empty initially. Im running the program on a ...
6
votes
3answers
108 views

constexpr SmallVector - std::vector like container on the stack

2 years ago I did this: SmallVector - std::vector like container on the stack now, 2 years later, I am reinventing the wheel again, this time with fully constexpr SmallVector. This time, because I ...
6
votes
2answers
1k views

Algorithm that generates orthogonal vectors: C++ implementation

Recently I asked the similar question, but the algorithm was implemented in Python. Now I've tried to implement the same algorithm, but in C++ (I'm very new to it): ...
16
votes
2answers
252 views

YAVI (Yet another vector implementation)

I am a C# game developer currently learning C++. I am trying to implement some simplified STL containers. Here is my implementation of vector, which does not have the allocator (because ...
2
votes
0answers
38 views

Leetcode Finding Maximum Area of Island Solution

Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are ...
3
votes
2answers
99 views

Quaternion and Vector3 transfomation Math

hi I have made and AI for my enemies which works perfectly but a particular section of code is repetitive and I feel that it can be optimised ...
2
votes
3answers
133 views

Modeling, view and projection transformation using vector and point in homogenous form

I know this is horrible code. This program is for performing modeling, view and projection transformation. The program reads input from scene.txt and outputs the <...
4
votes
1answer
70 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 ...
6
votes
1answer
147 views

STL-like vector implemention in C++

I attempt to write a STL-like vector, mostly to figure out how it works. I wonder which parts look weird or what I made stupid. Any kind of comment is appreciated: alloc.hpp ...
4
votes
3answers
144 views

Fast-resizing uint8 buffer

I wanted a buffer like std::vector<uint8_t> which is very fast at resizing, and it does not require byte initialization (it resizes to 16K, then to 2-4 bytes, ...
9
votes
2answers
134 views

Generic data structures in C

I'm new to C, and I thought a great way to learn would be to implement some generic data structures and algorithms. So far I've implemented a linked list and a dynamic array. Both are generic, the ...
5
votes
3answers
1k views

A STL-like vector implementation in C++

I'm implementing a STL-like vector with the essential functionalities. I would like to know what is good in this code and what is bad. In terms of everything (memory usage, functions implementations, ...
9
votes
2answers
340 views

Read file into vector<byte>

I need to read a range of bytes from a file and return it as a std::vector<std::byte>. My current code looks like this: ...
9
votes
2answers
2k 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 ...
10
votes
3answers
275 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 ...
1
vote
1answer
90 views

Vector calculation in Rust

Hi I am trying to get into Rust by implementing a small library for vector calculations. I am mainly asking to point out whether I chose a valid approach. I also am interested in comments on the ...
4
votes
1answer
272 views

C# System.Numerics.Vector<T> Clamp

The software that I develop uses large floating-point arrays up to the maximum size that can be allocated in C#. I have a large number of algorithms such as convolutions and filters that get executed ...
1
vote
0answers
28 views

Average histogram combining multiple files and vector of vectors (in c++)

I run a program of simulation N times (I use each time a different random numbers to initialize it). The results of the program are stored in 2N directories: every run produces two approximations. The ...
6
votes
2answers
299 views

Simulation of a banking system with an Account class in C++

I have been learning C++ and recently I have started practicing classes. I made this simulation of a banking system with an Account class. I would like to hear feedback on my code, what is good - what ...
1
vote
1answer
148 views

Clone Vector in rust except at one index [closed]

Let's consider you want to clone all items of a vector orig except the item of index i should be taken from alternative value <...
4
votes
1answer
139 views

std::vector free list

I'm trying to implement a free list by using a std::vector as its growable buffer. The reason I made this instead of just adding/removing elements directly into a ...
2
votes
0answers
316 views

VBA array functions: push, pop, shift, unshift

I want to write my snake game procedurally, using as much windows call as I can so as to practice. Looking into GetAsyncKeyState to capture keyboard inputs and play sound functions. Also making a ...
7
votes
5answers
1k views

Vector-transposing function

I profiled a library I'm writing that uses vector transposes and found that I am spending a good bit of time doing the following transpose. I am using a std::vector ...
6
votes
1answer
1k views

Implementation of thread-safe vector

I have implemented a thread safe vector, based on std::thread and std::vector. I am new to many of the patterns used in threading and was wondering if there's a more efficient way the locking can be ...
4
votes
3answers
857 views

Get length of the longest sequence of numbers with the same sign

I need to get length of the longest sequence of numbers with the same sign. Assumes that zero is positive. For example: ...
11
votes
2answers
146 views

Dynamic vector of void* in C

I have implemented a simple dynamic vector library in C. It is a header-only library. Full library listing - void_vector.h: ...
8
votes
2answers
997 views

C++11 Vector with move semantics

I am practicing move semantics and placement new by writing a custom Vector class but I am not confident that I use them right. I would really appreciate some pieces of advice regarding my code. Here ...
10
votes
3answers
1k views

Simple re-implementation of std::vector

Here is a simple reimplementation of most of std::vector. I want to check if I implement it correctly but the standard libraries source code is not very readable ...
3
votes
2answers
169 views

Simple Matrix Template Class

I wanted to make a matrix template class to see if I can learn how to use templates, work on figuring out the indexing in loops, and making an interface so the user can know if an operation will work. ...
1
vote
1answer
66 views

Header-only vector implementation in C

I tried to make a generic, header-only vector thingy I can use in other projects in the future. I omitted documentation comments because it's already quite long. ...
8
votes
4answers
2k views

Most efficient way to find an entry in a C++ vector

I'm trying to construct an output table containing 80 rows of table status, that could be EMPTY or USED as below ...
4
votes
2answers
862 views

Data Structures for Counting Duplicates and using std::vector::erase

Problem Dupe detection for a vector of ints. I simply want a count of the unique input characters that occurred at least twice. The goal is to count a dupe only once and ignore that input character ...
1
vote
0answers
151 views

Qsort in C++ using vector

I tried to make a simple qsort() function in a functional way, it takes a vector and a bool pred() Suggestions as to make it more functional, optimize it, and/or ...
3
votes
2answers
187 views

Manipulating and maintaining vector

Background I wrote a function update_list_v2(). And this function "maintains" a sorted list, g_list. ...
8
votes
6answers
861 views

Removing by indices several elements from a vector

From a sorted vector of indices (toRemove), I would like to remove from another vector (v) the elements at these indices. Note ...
1
vote
1answer
335 views

Median of a Vector assignment

I've been reading Bjarne's Principles in Programming and was given some code to demonstrate the usage of vectors and how we can return specific values for certain functionality such as mean and median....
1
vote
1answer
75 views

Convert a type u16 number to a matrix (Vec<Vec<u8>> or array) of 4 x 4

I am a Rust newbie and I am not familiar with all the iterator options. This is what I have so far. How can I make this better or at least avoid collecting twice into a Vec? ...
2
votes
0answers
378 views

A multithreaded, growable vector with immutable elements, which has wait-free reads

I wrote a small vector with a few lines of unsafe Rust. The idea is to have a vector, which can be read from simultaneously, but it needs the ability to grow. To realize that, the storage is ...
3
votes
3answers
89 views

Calculate total, minimum, maximum and mean from a set of distances

I have only begun to learn C++ and am reading through the book, "Programming Principles and Practices Using C++". This bit of code is my attempt to complete exercise 3 at the end of chapter 4. The ...
1
vote
1answer
573 views

C++ - Radix sort implementation

I have the following radix sort implementation: ...
4
votes
2answers
235 views

A simple Vector implementation

Just made a simple Vec class, nothing fancy but I am open to suggestions for improvements. Of course, this is not suppose to replace or used for the same tasks as <...