Vectors are sequence containers representing arrays that can change in size. For questions about geometric or algebraic vectors, use [coordinate-system] instead.

learn more… | top users | synonyms

1
vote
0answers
8 views

Short and Messy Polybius Square

I attempted to recreate the Polybius square, also called the Polybius checkerboard, which was used in Ancient Greece for cryptography. Since it is an uncommon cipher, it is nowhere on Code Review. ...
-1
votes
0answers
25 views

Libgdx/Java - How to find the distance between multiple objects in an array [closed]

So I'm currently working on a game where multiple meteors spawn and you have to avoid them. The problem is the meteors sometimes spawn overlapping each other, which I don't want. I want them to spawn ...
-2
votes
1answer
39 views

Finding the lowest missing integer in a vector containing negative and positive values [closed]

I'm writing an operation to find the lowest missing element of a vector, V = 1..N + 1. This has to be performed in \$O(N)\$ time complexity. Solution One: ...
0
votes
2answers
225 views

Capital Movement CodeChef challenge [closed]

PROBLEM Suppose there are 'n' cities in a country out of which, one is the capital. All of the cities are connected through 'n-1' roads so that it's possible to travel between any two cities ...
0
votes
2answers
88 views

LSH hashcode generator function

For building an LSH based system in Python, I need to have a very fast calculation of the hashcode. I won't need to explain here the LSH algorithm itself, but I need help in improving performance of ...
7
votes
3answers
247 views

Sort Characters By Frequency

I solved this problem. Problem Statement Given a string, sort it in decreasing order based on the frequency of characters. Example 1 Input: "tree" Output: "eert" ...
-4
votes
1answer
35 views

Find element in 2D matrix where rows and columns are sorted

Elements of a matrix are given in sorted rows and columns. I want to find the element in an optimized way. First, I will get the last element of a row, which will determine if a number can exist in ...
1
vote
0answers
19 views

Fast HashIndex (HashTable) “template” for indexes and arrays C++

Another in the long line of data structures I'm writing for my 2D isometric game. This is a hashtable that only handles indexes, hence eHashIndex. It does not copy ...
3
votes
1answer
72 views

Partition Equal Subset Sum Challenge LeetCode

I solved this problem in LeetCode. Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both ...
2
votes
1answer
53 views

Simple class to mimic a dynamic array

for my c++ class I was asked to write a class with the following characteristics: Implement a vector replacement that operates only on integers (you don't need to use templates like the normal STL)...
5
votes
1answer
92 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 ...
4
votes
1answer
66 views

Keep elements present an odd number of times in an unsorted vector

From an unsorted vector of integers, I would like to keep only elements that are present an odd number of times and have them sorted. Below is an example of a working code. ...
-1
votes
2answers
75 views

Calculating the number of extended family members [closed]

The problem here says to find the number of extended family members of the president, N people live in Sequence Land. Instead of a name, each person is identified by a sequence of integers, ...
1
vote
0answers
68 views

Performance issue when dealing with bits

Here is the slow part of my code ...
2
votes
1answer
74 views

Jolly jumpers programming challenge

I have posted my solution to the jolly jumpers programming challenge(detailed here) for your review: A sequence of n > 0 integers is called a jolly jumper if the absolute values of the ...
6
votes
3answers
116 views

Interpreter programming challenge

I have posted here my working and accepted solution to the intepreter programming challenge (detailed here) for your review. The challenge is as follows: A certain computer has 10 registers and ...
8
votes
2answers
116 views

Graphical editor programming challenge

I have posted here my working and accepted solution to the graphical editor programming challenge (detailed here) for your review. The program recognizes the following image editing commands: ...
2
votes
2answers
114 views

Remove duplicates from a sorted array

I have solved the LeetCode Remove Duplicates From Sorted Array problem: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. It ...
1
vote
2answers
65 views

Creating a custom template container class (vector alike)

What can be done better? What should I learn to make these tasks better and more efficiently? The template (template.h): ...
3
votes
3answers
75 views

2D Vector: Loading values from .txt file

I've written a program that runs through a matrix of numbers, ranging from 0 to 2, and stores the results in a 2D vector. I'm using the values in the 2D vector as the profile for a tile map for a ...
2
votes
1answer
53 views

Invert-range operation in a circular vector

I implemented a invert-range operation in a (logical) circular vector. A circular vector is a vector without a logical starting and ending object, or, equivalently, the successive element of the ...
1
vote
1answer
113 views

C++ std::vector with always valid iterator/pointer/index/key

Motivation: Have std::vector<std::unique_ptr<T>> accessibility at std::vector<T> speed. ...
1
vote
1answer
78 views

SmallVector - std::vector like container on the stack

SmallVector is almost same as std::vector except it keeps its data inside a large array. Similar to ...
3
votes
2answers
134 views

Code for calculating the books dispatched

Recently I came across this, here is an excerpt from it, This is another problem about Indraneel's library. His library has one long shelf. His books are numbered and he identifies the books by ...
1
vote
1answer
41 views

Delete the node at index i from its current position and insert it after node at index j

I was trying to create a function to delete the node at index i from its current position and insert it after node at index j ...
10
votes
2answers
626 views

Implementation of a generic List

I have only been self teaching myself programming on and off for about 5 months. The purpose of me writing this class is to incorporate the knowledge that I have gathered since I started. ...
2
votes
2answers
91 views

Rotation view for std::vector

I have this view class for constant time rotations of a std::vector: ...
2
votes
1answer
30 views

Robustness of this first difference function

Here is a first difference function I threw together for a quick check in another program: ...
2
votes
1answer
65 views

Speed up code based on map with vectors as values

Following is the piece of code which represents the bottleneck of my application: ...
0
votes
0answers
55 views

Optimizing Text Data Import From MatLab

I want to import some data to a 2-D vector. The data type is double like 5.8774718e-39, and the size is ...
1
vote
2answers
122 views

Merge sort using c++ vectors

I'm still learning C++ and also algorithms. So I'm expecting to do a lot of refactoring. Here's my code ...
2
votes
1answer
89 views

measuring the time taken to copy a std stl container

I'm trying to measure the time taken to copy a std::vector<someObject>. Would like to know if this is a correct approach. I tried to do some trivial ...
2
votes
3answers
317 views

Printing out vector<string> char by char

I have learned a bit of C in university and I'm now learning C++ independently. I'm trying to print out std::vector<std::string> ...
8
votes
5answers
172 views

Counting pairs of integers whose sum is less than a given threshold

Recently I was going through this codechef problem while practicing for the upcoming zoc. The problem asks to calculate number of combinations of the given numbers where the sum is less than another ...
5
votes
2answers
126 views

Creating a minimax tree recursively

I am currently working on creating a tree (this is my learning process of creating a minimax tree and am starting towards minimax tree from here) with multiple nodes recursively. Can anyone please ...
2
votes
4answers
109 views

My own std::vector

I've made my own std::vector but it's the first time that I work with template and new/delete. The code works, but surely there are a lot of things that are wrong. ...
1
vote
1answer
44 views

Simple Factor Class

I have a class which lazily factors numbers. It provides the user with these methods: getFactors returns a ...
0
votes
1answer
64 views

Follow up: Simplified Implementation of ArrayList in C++

This question is a follow-up to the my earlier code posted here. In the original question, I created a simplified version of C++ std::vector/...
7
votes
3answers
208 views

Simplified implementation of std::vector in C++

I implemented a simplified version of a C++ std::vector/ArrayList learning from this link. From it, I tried to write an ...
3
votes
2answers
293 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
1answer
175 views

Partial ArrayList implementation in C++

I've implemented a C++ version of Java ArrayList. It doesn't contain all the functionalities such as AddAll and iterators and such, but I still would appreciate criticism to my code correctness, style ...
4
votes
2answers
87 views

How can I use vector for entering numbers?

I want to enter names, student numbers and student scores and display this information. I used arrays in this way: ...
0
votes
0answers
43 views

Octree population is too slow

EDIT A few code formatting corrections, can not do it better as I can't get to my working station, editing on my phone I've got basic octree structure for voxel storage. The tree is populated by ...
7
votes
1answer
126 views

Vector implementation in C++

I started this because I thought it would be a fun and easy way to brush up on my C++. It turned out to be a lot more complicated than I thought. I learned about ...
2
votes
3answers
99 views

Place integers into a vector, sum each adjacent pair, refill vector with only the sums of each pair i.e remove all the original data from the vector

Is there a quicker/better way of doing this, mine works great for small vectors but if i get a vector with an arbitrarily large size this would probably take forever to run. Thanks.(P.S. its been a ...
7
votes
5answers
771 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 ...
2
votes
1answer
92 views

Auto-resizing array, that accepts negative indexes

I've been coding a helper container template to contain tiles in 2D games. What I figured out I would like when writing code for my games is forgetting all resize stuff, allowing negative indexes (for ...
2
votes
1answer
148 views

std::vector with custom growth factor

So, yes, I know that "you shouldn't derive from std containers" but by now it's more of philosophical rule in my mind than a technical one. I've googled again for the one fundamental reason one should ...
5
votes
4answers
1k views

Find all instances of element in array

I've created a function to return all the indices where an element is to be found in an array. If it occurs twice or more, all the respective indices will be returned, for now it returns them in ...
4
votes
2answers
104 views

Print max no of recent duplicate words

I am new to C++, learning from the book primer C++ The exercise: Write a program to read strings from standard input looking for duplicated words. The program should find places in the input ...