An array is an ordered data structure consisting of a collection of elements (values or variables), each identified by one (single dimensional array, or vector) or multiple indexes.
0
votes
0answers
6 views
A Java subclass of ArrayList that supports rotation in constant time - follow-up
(See the previous (and initial) iteration.)
I have more progress on java.util.ArrayList subclass that supports rotations in constant time. See what I have now:
...
3
votes
1answer
27 views
Weaving an array
In preparing this answer, one of the components was an algorithm to rearrange a sorted array in a particular way. To put it succinctly, here's the problem description:
Given an array \$A\$ with ...
3
votes
1answer
39 views
Project Euler #127 abc-hits
Problem (Rephrased from here):
The radical of \$n\$, \$rad(n)\$, is the product of distinct prime factors of \$n\$. For example, \$504 = 2^3 × 3^2 × 7\$, so \$rad(504) = 2 × 3 × 7 = 42\$.
...
6
votes
3answers
260 views
A Java subclass of ArrayList that supports rotation in constant time
(See the next iteration.)
I have subclassed java.util.ArrayList in order to be able to "rotate" it in constant time simply by moving a finger index. See what I ...
0
votes
2answers
47 views
Minimum element in a sorted rotated array
A sorted array [0,1,2,3,4,5] when rotated n times (3 times in this case) becomes [3,4,5,0,1,2], meaning elements in the front move to the end. The code below finds the minimum element in this array, ...
5
votes
5answers
203 views
Removing duplicates in an array
Problem: Remove duplicates from a given array of integers.
I want this method to work without using data sets except an array.
My code is currently \$O(n^2 + n) = O(n^2)\$. How do I shorten this? My ...
2
votes
1answer
66 views
Object-to-array flattening function
I have written a function that is designed to convert an object into an array of key/pair values ("flattening it") like so:
Input
...
5
votes
1answer
319 views
Anagram finder in F#
I've been learning F# for a month or so and I'm wondering how good my "functional" aspect of coding is. When I first started, I did this using an iterative approach with a lot of <- and mutables ...
3
votes
1answer
71 views
Initialize and sum an array in Java using threads
This bit of code initializes an array of any given size where each index corresponds to a thread and a value. That is, index 0 has 0, index 1 has 1, and so on. Then, the values, 0 to n, in the indexes ...
4
votes
2answers
53 views
Counting numbers whose digits all go up or down
I have created a program which takes a value x and uses this value to create a power of ten value like so 10 ** x.
This has ...
0
votes
2answers
41 views
Partitioning an array of objects into four arrays by one attribute
I have an array of API objects, below is an example of one object:
...
0
votes
2answers
48 views
PHP alternative syntax confusion
Newbie to PHP.
Trying to output the results of an array inside a foreach loop. I have got the following code but I cannot understand what to do with it next.
Mainly;
Where/how do I start and end ...
2
votes
1answer
20 views
Printing the minuend and subtrahend in a Minimum Difference algorithm
I have a Minimum Difference algorithm, and I wanted to expand on it by printing the actual elements that were subtracted. I'm just wanting to know if this is the best way to do it.
...
1
vote
1answer
82 views
NDArrays in C: slicing/transposing/polynomials
This is the primary module for my APL interpreter. The general idea is motivated by my two Stack Overflow questions, but the details I fear are easy to get wrong and I suspect there are a few corners ...
2
votes
1answer
77 views
Poker app in C#
I am developing a poker application using C#. It is almost done, and I'm looking for improvements. One of the things I wonder is whether I should change my method that checks if the player has a ...
2
votes
2answers
84 views
2
votes
2answers
57 views
4
votes
2answers
81 views
DoublingQueue in Java
Inspired by this CR question, I decided to create my own queue! If you guys see anything taboo or have any improvements, please let me know. Ultimately I want it to be feature rich and bug free, with ...
-1
votes
1answer
50 views
&(array[index]) vs (array + index) [closed]
So I'm working with a function that returns a pointer to a list item. Right now, I'm using:
...
11
votes
5answers
540 views
FiniteArrayQueue type with interface and unit tests
Doing some exercises on basic data structures, I learned about queues, and decided to roll my own to better understand how a basic queue can function. As the name indicates, this Queue is made from a ...
2
votes
2answers
127 views
Efficiency of vector like class
I've written a vector-like class in C++ and I'm trying to figure out issues in efficiency. When I use clock() to measure the time taken to emplace objects, ...
2
votes
2answers
85 views
Array-based deque in Java
Are the conditions which I have included for insertion and deletion from front and rear sufficient and necessary? Have I missed some condition check? Or have I included some redundant condition?
...
0
votes
1answer
39 views
Java two arrays of audio, or one array? how to determine the most effective
Okay so I have some code, I want to play some audio of two byte arrays, I was wondering whether it would be better to play them as two separate arrays both calling the method or to put them into one ...
-3
votes
1answer
110 views
Rewrite a javascript function in a better way
From the below array $data, I place price for each month for one category in first array. If no data is found for the particular category for a month, inset 0, ...
1
vote
0answers
10 views
Optimize KnockoutJs Pagination Computed Function
I have written a function that builds an array of paging options for rendering on the view.
I have modelled it after DataTables for jQuery, a live example with lots of data is available here: ...
2
votes
2answers
55 views
Make binary search tree from sorted array
Here is my code for converting a sorted array to a binary search tree. Please review and let me know the improvements or some better way of solving this.
...
3
votes
0answers
35 views
Implementing a templated Array class
I have implemented an Array class using templates. I have used a std::allocator object for memory allocation. Will it be better to use operator new along with placement new for memory allocation?
...
-2
votes
1answer
43 views
Implementing Arrays in Java Class
I have the following code to write:
Modify the Student class so that instead of 3 tests you will now have
an array of 100 tests. However, not all of the scores may be set. You
need to add an ...
8
votes
4answers
121 views
Python Implementation - Conway's Game of Life
This is my implementation of Conway's Game of Life in Python. Now since I am a novice coder, naturally I have some key doubts:
The usage of idioms and code redundancies - Are there any small ...
3
votes
2answers
70 views
2
votes
1answer
52 views
Matrix column switching
I'm currently working in the math library for a game framework that I'm writing and am working to improve some functionality that was affected during a refactor.
Formerly, my ...
4
votes
2answers
68 views
Generate all permutations in C
I have written code for generating all the permutations in C as explained here. How can the code be optimized? Are there any memory leaks?
...
6
votes
2answers
216 views
Automation of array allocation in C
I recently have been working on moving from projects written in Java and C++ to C and realized that the lack of std::vector in C makes it a bit more difficult to ...
6
votes
3answers
224 views
Loading tab-separated tweet data into an array
I'm working on this school project and was wondering if there was any way of storing this information better, faster, more professionally. I'm also restricted to only using an array; don't ask me we ...
2
votes
2answers
79 views
Slice chunking in Go
I have a slice with ~2.1 million log message strings in it that I am parsing for regular expression matches. For any matches, I add it to a local slice and then return said slice.
...
1
vote
0answers
22 views
Rotating an array left or right [closed]
I'm trying to rotate an int array either left, or right, and I ran into some problems trying to rotate higher numbers. I know what is wrong, but I can't figure out a way to fix my code. Thanks for the ...
2
votes
3answers
99 views
Pascal Triangle implementation in C#
This is my attempt to implement the Pascal Triangle in C#. It is meant to calculate and return a pascal triangle of size n (which it takes is through the parameter ...
3
votes
2answers
53 views
Data Table Report Class
Most of the VBA I write is to produce tabulated reports from spreadsheet data.
So, here is my attempt at creating a CLS_Data_Report class.
Properties:
a ...
4
votes
4answers
292 views
Swapping characters pairs in a string
I have to swap the characters in a string before sending said string to a device to show the information sent through a LCD, the method I developed is as follows:
...
2
votes
2answers
63 views
Function to combine arrays of associative arrays
I recently create a function to combine some arrays of associative arrays in a single array in response to a stackoverflow question, where you can found more details about this.
The function works as ...
2
votes
0answers
81 views
Nested loops with linear array
i have found this article on how to loop through multi-dimensional arrays quickly.
http://nadeausoftware.com/articles/2012/06/c_c_tip_how_loop_through_multi_dimensional_arrays_quickly
I am using ...
4
votes
1answer
76 views
Displaying a randomly sized array as a table
This program creates an integer array with a random size of 5-50 elements (inclusive). It then fills the array with random numbers between 0 - 100 (inclusive). The interesting part comes when I then ...
3
votes
0answers
101 views
GSL-like array_view implementation
I've seen a couple GSL-like string_view-ish implementations on CR recently, but don't recall seeing anything like array_view yet ...
2
votes
5answers
173 views
Array is Balanced Array or Not
A balanced array is defined to be an array where for every value n in the array, -n also is ...
4
votes
1answer
33 views
Array is Twinoid Or Not
A twinoid is defined to be an array that has exactly two even values that are adjacent to one another. For example ...
4
votes
2answers
192 views
Array is MinMax Equal or Not
An array is defined to be maxmin equal if it contains at least two different elements and the number of times the maximum value occur is the same as the number of times the minimum value occur. So ...
4
votes
2answers
65 views
Find all integers between m and n whose sum of squared divisors is itself a square
Divisors of 42 are : 1, 2, 3, 6, 7, 14, 21, 42. These divisors squared
are: 1, 4, 9, 36, 49, 196, 441, 1764. The sum of the squared divisors
is 2500 which is 50 * 50, a square!
Given two ...
3
votes
3answers
138 views
Algorithm to find leaders in an array
An element in an array X is called a leader if it is greater than all
elements to the right of it in X. The best algorithm to find all
leaders in an array.
Solves it in linear time ...
7
votes
3answers
662 views
Sum all numbers in a range
I have implemented the "Sum All Numbers in a Range" challenge from Free Code Camp quoted below.
The code works like a charm, but I don't think it's idiomatic. The challenge hints imply I should be ...
4
votes
3answers
446 views
Write a function named isSuper that returns 1 if its array argument is a isSuper array, otherwise it returns 0
An Super array is defined to be an array in which each element is greater than sum of all elements before that.
For example:
{2, 3, 6, 13} is a Super array. ...