An array is a data structure consisting of a collection of elements (values or variables), each identified by at least one index. All the elements of an array are stored adjacent to each other.

learn more… | top users | synonyms

-1
votes
1answer
38 views

Random Array Element [on hold]

I am trying to randomly choose 5 elements from an arraylist. For some reason, it always chooses 0 as the random element. Any help?? Here is my code that I have so far. import java.io.BufferedReader; ...
0
votes
0answers
21 views

BAD ALLOC: dynamic memory allocation [closed]

This is what i am doing. int main() { double *array1; array1 = new double[245629]; double** array2 = new double*[245629]; for(size_t i = 0; i < 245629; i++) array2[i] ...
1
vote
2answers
61 views

Performance: getting first value from comma delimited string

I've got a string that has values that are delimited by comma's, like so: $var = '1,23,45,123,145,200'; I'd like to get just the first value, so what I do is create an array from it and get the ...
0
votes
0answers
29 views

Increasing program efficiency

I have written a Manchester Encoding encoder / decoder based on my misconception of how it works (whoops). My encoder accepts an array of ones and zeroes, and returns the 'manchester encoded' data ...
1
vote
1answer
46 views

Merge 2 arrays, when one is larger and can accomodate smaller

How will you merge two sorted arrays, when The longer array has empty spaces to accomodate the second array. Complexity: O (items in longer + items in smaller). Request for making code concise, ...
1
vote
0answers
11 views

Add item to an Array 2D using LINQ

I've wrote a generic function to add an item to an Array 2D This is what I have: Private Sub Add_Item_Array_2D(ByRef Array_2D As String(,), _ ByVal Items As String()) ...
3
votes
4answers
256 views

Book program with arrayList

I have this Book program that contains 2 classes: Book and Library. I have the Book class done, but need some help on the Library class. Please help me check my code. I can provide the Book class if ...
0
votes
1answer
37 views

Testing if numbers in the array can be added up to equal the largest number in the array

Okay, here's a challenge at Coderbyte that completely stumped me. I came up with a solution, but I know it is flawed. Have the function ArrayAdditionI(arr) take the array of numbers stored in arr ...
5
votes
2answers
125 views

Finding greatest value in array smaller than x

Code review requested to make this code simpler, cleaner, and better. Input array is sorted. This program finds the greatest number smaller than x. So, in an array [10 20 30 40] and x = 25, the ...
2
votes
1answer
81 views

array with reusable elements

I need array to store elements, but I don't want to make memory allocations at runtime. So I reuse elements. Some fields are never changes so as I reuse elements I need to assign those fields just ...
3
votes
3answers
174 views

Reversing the elements of an array

Any way to make this more concise/efficient? // Write a loop that reverses the elements of an array. #include <iostream> #include <iomanip> const int SIZE = 10; void reverse(int ...
2
votes
1answer
36 views

2-dimensional “wrapping” array

I'm writing a simple JavaScript game, which uses a 2-dimensional array as the main data structure. I wrote this function-class-thing that allows me to give any two integers, positive or negative. ...
-1
votes
1answer
96 views

Unique hashtag extracting [closed]

I am trying to find unique hashtags from a tweet that a user inputs. I have the code to find the number of times a word is used in the input, but I just need to know the number of different hashtags ...
1
vote
1answer
68 views

Can someone review my implementation of an ArrayList?

public class ArrayList<E> implements List<E> { private static final int defaultMaxSize = 10; private int maxSize; private int size; private int currentPosition; private ...
2
votes
1answer
50 views

Anagrams for a given input 2.0

This question follows on from :Previous Question Here is what my reworked code looks like. I neatened it up as much as I could. Changed some of the semantics of it. I also tried to add some faster ...
1
vote
1answer
37 views

Simple Nick Namer Review Request

Hi guys this was my first project, I redid it after getting critique on my second project. Can I please get some Critique on this project too? The code is pasted in sections, but it appears exactly ...
6
votes
4answers
203 views

Anagrams for a given input

This question is the first draft, my new revised code is here: Anagrams for a given input 2.0 Here is my code that I wrote, which basically lists the anagrams for a given input. I did this by ...
9
votes
4answers
224 views

Why is this code so much faster (relatively) in IE7?

Here's some code that I ran through jsperf to assess its performance. The first test (named EvalLengthBefore++ in the images below) is the way I would consider normally looping through the elements of ...
1
vote
1answer
63 views

Switching directions in iterating 2D arrays

I had to do this in a course a while back: make {1,2,3,4,5,6,7,8,9} into {{1,2,3},{6,5,4},{7,8,9}}. When doing it, I just made the inner for-loop do all the work. But most of my friends had a Boolean ...
0
votes
2answers
356 views

Find out the second Largest Number in an Array of Elements

Hello i have written this code to find second largest element in an array of random integers if it needs to be optimized then do comment on it. i'm not confined to it your precious code will always be ...
9
votes
1answer
267 views

Review my sorting algorithm please!

I've been playing around and reading up on some sorting algorithms, and i decided to try writing my own.. It turned out to be quit fast (Compared to the others shown in the image below). I'm i'm very ...
1
vote
3answers
84 views

Improving function that compares two strings

I'm learning C and have made this very simple function to compare two strings. I would like to know how it can be improved: int match(char* string1, char* string2) { size_t i = 0; while ...
1
vote
2answers
87 views

A better way of checking if index is out of bounds

For a simple project, I represent a two-dimensional grid as a one-dimensional array, with both row and column indices between 1 and gridHeight. When retrieving a cell from the grid, I first need to ...
0
votes
2answers
77 views

Is this an efficient way of organize an array?

The array is dynamic, can be with 7 or more keys, except the first key never changes. Array ( [0] => Array ( [ProviderID] => 1010 [ProviderName] => ...
1
vote
3answers
128 views

A custom Java collection which doesn't support nulls

I am making a GWT application and have to prevent client code from using null values in collections. I found an answer but GWT doesn't support Queue and its implementations as the GWT documentation ...
1
vote
2answers
94 views

Eliminating duplicates in an array of ints

public static Integer[] eliminateDuplicate(int[] a) { if (a == null) { throw new NullPointerException(); } List<Integer> list = new ...
0
votes
1answer
257 views

Searching multidimensional arrays

I have been trying to parse results and make sure when I am doing so that I don't repeat the same data. I tried to use a few different options built into php with no luck. I did find an example of a ...
1
vote
3answers
104 views

Putting array name in variable and shortening code

I'm a beginner in C# and am doing a simple programming exercise. I would like to put the Item.price and Item.Name into Listbox2. Is it possible to put the array name into a variable and iterate with ...
1
vote
1answer
62 views

Simplify code using array

I am trying to simplify the amount of code required here using arrays, I feel like my foreach loop is still excessively long. Any advice would be appreciated. $date_list = Array( Array( 'age', ...
1
vote
2answers
92 views

What is a better way to get unique array Items based on key in PHP?

I'm trying to achieve a set of unique array with my following function. The Function: /** * uniqueAssocArray Removes arrys which have same keys * @param Array $array Array to get unique items ...
2
votes
3answers
148 views

Better way to write generic method to convert List<List<T>> to T[][]

I was working through getting myself past the creation of a generic method, that converts a List<T> or List<List<T>>, to T[] or T[][] respectively. Well, let's just consider a ...
7
votes
4answers
677 views

Removing duplicate values from an array

Here is my code for removing duplicated values from an array. I think I tested it with the most possible cases. Any suggestions or bugs? public static int[] removeDuplicates(int[] arr){ int ...
2
votes
2answers
345 views

Review implementation of stack by using array in C

This question has become long after many updates. Click here to go down. I have implemented stack using arrays in C. Please give me suggestions on how to improve it. The purpose of writing it is ...
1
vote
2answers
162 views

Am I on the right track with this random number array?

Is this the best way of doing this? I wanted to make sure the grammar is correct when the array is output. 1 car, 2 cars. The output is correct but is there an easier way generally? I just want to ...
1
vote
1answer
68 views

Is there any better way to fetch two tables in one statement or query?

The 'Do' method is for prepared statements and returns (by fetchall()). I am also using two looping statements. Is there any better way to fetch two tables in one statement or query? If not, what ...
1
vote
3answers
140 views

Reference counted dynamic byte array in C

What? I have a reference counted dynamic byte array written in C. I'm currently using this implementation in a FIFO fashion. Particularly reading data from files into the arrays, then parsing the ...
2
votes
1answer
89 views

What would be the optimal way to address these arrays

I think the arrays here are slowing down my code due to incorrect usage. There is a lot of stuff going on here, it's understandable if nobody responds. Just looking for some pointers. Thanks. for ...
3
votes
1answer
216 views

C++ Compare 2 Arrays

I started reading C++ Primer a few weeks ago and there's an exercise that asks you to compare 2 arrays for equality. The code I made works, but is it good? What should I fix? If the number of ...
6
votes
2answers
882 views

Trying to build a student grading array program

I have a program to calculate and show the grades for 4 students and 3 tests. I want to calculate the average for each student, the average of the test scores for each test, and the average of the ...
1
vote
1answer
106 views

Pure PHP array_diff_assoc_recursive function

For my application, I was using array_diff_assoc, when I noticed it was returning the wrong value. I was using multidimensional arrays, therefore I needed a array_diff_assoc_recursive method. I ...
1
vote
1answer
64 views

Missing element from array (D&C) - code design/aesthetic improvement

I am trying to implement in C/C++ a 'classical' Divide and Conquer algorithm which solves the following problem "Given an array of n-1 numbers (int) from 0 to n, find the missing number". I am using ...
4
votes
0answers
207 views

Cross-browser DOMTokenList object and wrapper function. Failures and improvements?

So, this is my first question here at Code Review. I have been looking for a Cross-browser solution for DOMTokenList and element.classList. I wasn't able to find much for DOMTokenList and the ...
2
votes
2answers
147 views

Storing Hierarchical Data in a Database

in a extension tho this post Pages system PHP/SQL I've created this class/script to handle Multi-dimensional Menus wich data it's stored in a DB... I need some feedback and new ideas... (all of this ...
0
votes
1answer
40 views

Check for existence and assign

Is there a smarter way to do the following without the $result variable and without the if-statements? ... $description = BIG ARRAY $result = array('error' => '', 'amounts' => ...
2
votes
0answers
23 views

Summing 2D NumPy array by multiple lables

Each element of the array is a coordinate (x, y). Each coordinate has two labels. Goal: sum the elements that have the same two labels. How can this be faster? >>> import numpy ...
1
vote
6answers
204 views

Remove specific consecutive element in array

I'm trying to reduce consecutive elements of array to one, but not for all values like: {3,0,0,0,3,3,3,0,0,0} => {3,0,3,0} but for specific one, in my example 0: {3,0,0,0,3,3,3,0,0,0} => ...
9
votes
5answers
1k views

Repetitive code driving me crazy!

Ok, So first I must say that everything I know about coding I have learned on my own in my spare time so bear with me if my code is primitive, but please, I am open to any comments to make me ...
2
votes
0answers
110 views

Implementing recursive filters with Haskell/Repa

I recently learned Haskell, and I am trying to apply it to the code I use in order to get a feeling of the language. I really like the Repa library since I manipulate a lot of multi-dimensional data. ...
3
votes
3answers
136 views

re-write javascript array

I am using a long array of over 300 var & 7,000 lines of code written like this: var a = []; var b = []; var c = []; var d = []; var e = []; a[0] = "a"; b[0] = "b"; c[0] = "c"; d[0] = "d"; e[0] ...
0
votes
2answers
79 views

Comparing two arrrays

I have two arrays: first one is ip addresses from billing for blocking second is ip addresses from firewall - already blocked My task is, compare it, and if ip address new in billing list - block ...