Tagged Questions
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
1answer
22 views
LeetCode Rotate Array
I have started learning Java and was trying to solve some easy problems from different websites like HackerRank and leetcode.I am relatively new to programming so please don't mind if this is too ...
5
votes
0answers
52 views
Simple Conway's Game of Life implementation in Java
I wrote a simple implementation of Conway's Game of Life in Java using 2 arrays and for loop and used StdDraw library for plotting generations.
It turned out that ...
0
votes
1answer
30 views
Change non-diagonal surrounding elements in a 2-D array
I'm a beginner working through an exercise on ruby arrays. Given a two-dimensional array with 0's and/or 1's, it should return an array with the non-diagonal surrounding elements of 1 changed to 1 if ...
0
votes
1answer
72 views
Custom Dynamic Array
Pretty simple class but just want to make sure I've approached it correctly.
...
3
votes
1answer
56 views
Generic variable-size array
As stated in the tags, I'm a beginner to C. This code implements a dynamic array (List in .NET, vector in C++, etc) for any ...
-3
votes
1answer
62 views
Nim Game with Arrays [closed]
I am suppose was to incorporate arrays in my NIM game java code, so that we can allow the user to decide on how many heaps are in play. I am stuck and have no clue how to do so.
Heap Class
...
0
votes
2answers
44 views
Create an array with at least a given number of bits
I use this declaration for an array which must contain a bit for every minute in a day:
...
-2
votes
0answers
22 views
3
votes
0answers
58 views
Google CodeJam 2016 - Ruby - Counting Sheep
https://code.google.com/codejam/contest/6254486/dashboard#s=p0&a=0
I just wrote a small Ruby class to solve the first of the challenges in the G CodeJam. I am not strong at this sort thing so ...
-2
votes
1answer
80 views
3 exams, 20 students: calculating the per-student average score [closed]
I'm a little curious... I have to work on a program in which a student takes 3 exams and the average is taken from the 3 exams that a student takes. It then goes into a form of a table, where one ...
-1
votes
0answers
31 views
Dynamic boostrap dashboard
I am creating dynamic dashboard, where each column of row will be considered a screen. The system picks various screens as an array that is formatted as follows:
...
3
votes
2answers
153 views
+50
Find median of two sorted arrays
Problem statement
There are two sorted arrays nums1 and nums2 of size m and ...
2
votes
2answers
102 views
Algorithm to rotate array elements in Ruby
I wrote this algorithm to rotate elements in an array. It's not very efficient, but it works. It has another disadvantage that it doesn't rotate right (it would be nice to pass it negative steps, for ...
0
votes
1answer
51 views
Shuffle array without duplicates
I made a function about random backgrounds
And those images will unique as possible. (Shuffle again after all gone)
My steps is :
Setup the array
Shuffle it
Do function (check if ...
-1
votes
1answer
36 views
merging json object
Hi I am trying to merging json objects which has common value.
This is original JSON
...
1
vote
4answers
79 views
Diff Two Arrays - return the symmetric difference of the two arrays
This is my challenge using JavaScript -> Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric ...
2
votes
1answer
64 views
Quiz program in Java
I have made this small quiz with 10 question and 40 JRadioButtons. One question and 4 JRadionButtons for each panel. So I had to ...
0
votes
0answers
38 views
AVL Tree Array Representation
In a school assignment I'm supposed to create a program simulate insertion, deletion, count nodes, and delete tree algorithm and displays the traversal, level order, and array representation of it. ...
2
votes
2answers
68 views
sum, range and rangeSum functions
Forgive me if this is too simple, but I'm a beginner trying to learn and understand. I came across an exercise to create these three basic functions, and this is what I came up with.
Any glaring ...
0
votes
0answers
19 views
Filter option for PFQueryTableViewController in Swift
I have a PFQueryTableViewController, and have create a separate TableViewController that allows me to select a filter option. When the user selects an option to ...
5
votes
1answer
95 views
C# Sorting array without using the bubble sort
I'm a beginner and like to experiment new things so today I tried to implement sorting method for an array without using any Sort and the actual challenge was to do ...
1
vote
1answer
42 views
5
votes
4answers
788 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 ...
1
vote
2answers
87 views
Fixed-length Stack in Java
I implemented a fixed-length stack in Java for use in my fractal generator program, an RPN calculator and my esolang interpreter. This is a generic stack, and goes over and above the call of duty in ...
0
votes
1answer
52 views
A Java subclass of ArrayList that supports rotation in constant time - follow-up
(See the previous (and initial) iteration.)
Compared to the previous iteration, I have added more methods that maintain the invariant required for constant time rotations, such as bulk add/remove, ...
6
votes
2answers
108 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 ...
4
votes
1answer
50 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\$.
...
7
votes
3answers
328 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
3answers
63 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
216 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
70 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
355 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
104 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
64 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
43 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
55 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
90 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
82 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
99 views
2
votes
2answers
57 views
4
votes
2answers
83 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
52 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
542 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
94 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
56 views
Playing audio from two data sources
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 array and play it from ...
-3
votes
1answer
111 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
11 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
57 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.
...