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
1answer
35 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 ...
1
vote
1answer
38 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 ...
1
vote
0answers
15 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: ...
3
votes
1answer
64 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 ...
8
votes
2answers
596 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 ...
2
votes
0answers
44 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 ...
4
votes
4answers
555 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 ...
2
votes
0answers
54 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 ...
3
votes
2answers
103 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: ...
4
votes
2answers
99 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 ...
5
votes
2answers
222 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 ...
8
votes
3answers
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 ...
3
votes
2answers
164 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 ...
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 ...
2
votes
2answers
89 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
87 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. ...
6
votes
1answer
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 ...
2
votes
2answers
87 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 ...
5
votes
1answer
73 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 ...
4
votes
1answer
76 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 ...
-2
votes
1answer
57 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
416 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-...
13
votes
4answers
7k views

Basic iterator supporting vector implementation

On the fly, I just implemented this iterator supporting vector class to understand how range-based for loop works. It's really basic but let me know what can be improved. Vector.h ...
2
votes
2answers
90 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 ...
10
votes
3answers
292 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 ...
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 ...
4
votes
3answers
167 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, ...
2
votes
1answer
51 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 ...
8
votes
7answers
2k views

An ordered set in C#

I need a generic data structure that ensures that its elements are unique. C# has HashSet<T>, great! As it turns out, the elements have to stay in the order ...
6
votes
3answers
279 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
262 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
46 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 ...
6
votes
1answer
159 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 ...
3
votes
2answers
112 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 <...
9
votes
2answers
155 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 ...
6
votes
2answers
2k views

3Sum implementation

I have recently started to work through the problems on Leetcode, for the sake of bettering my own skills as well as preparing for interviews. I was faced with the 3Sum problem which is: Given an ...
2
votes
0answers
471 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 ...
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, ...
6
votes
1answer
432 views

Given a vector and a target sum, returns zero-based indices of any two distinct elements whose sum is equal to the target sum

I am trying to solve 4. Two Sum from this set of C++ interview questions. As far as I can think this solution has a time complexity of \$O(n \log n)\$ can it be further optimized? Write a function ...
10
votes
2answers
2k 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: ...
8
votes
1answer
193 views

An Alternative Vector (Copy Assignment Operator)

This is a continuation of An Alternative Vector, taking a closer look at the copy assignment operator. In the following code, I am only posting the new version of the copy assignment operator; all ...
8
votes
4answers
323 views

An alternative vector

Based on this question (as a starting point) and a couple of other questions about rewriting vector in C++, I am planning to write another blog article to show the best way (or more precisely, the ...
1
vote
1answer
128 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
392 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
31 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
514 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
303 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 <...

1
2 3 4 5 6