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.
1
vote
2answers
87 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 ...
0
votes
2answers
65 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
37 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 ...
0
votes
3answers
85 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
59 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', ...
0
votes
2answers
51 views
What is a better way to get unique array Items based on key in PHP? [closed]
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
119 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
3answers
376 views
Java: remove duplicates from an array
Here is my code to remove duplicated values from an array. I think I tested it with most possible cases. Any suggestions or bugs ?
public static int[] removeDuplicates(int[] arr){
int end = ...
2
votes
2answers
297 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
142 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
58 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
113 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
87 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
140 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
224 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
92 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 ...
0
votes
1answer
44 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
169 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
117 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
36 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' => ...
1
vote
6answers
151 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
91 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. ...
2
votes
3answers
127 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
71 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 ...
2
votes
1answer
64 views
Making complex array initializations more readable
I have a function in the C++ program, which does simple computations and writes result to two arrays - result[53] and var1_new[53]. It contains two code blocks:
The first one -
double result[53];
...
2
votes
1answer
86 views
Sorting an array
I wrote this program for sorting an array of type String alphabetical without using compareTo() method so I am saying that if you can find errors in my program please tell me I will try to fix it.
...
3
votes
4answers
182 views
PHP - Don't repeat yourself?
http://plugins.trac.wordpress.org/browser/seo-content-helper/tags/1.1/get-data.php
Don't repeat yourself
I know of the "Don't repeat yourself". Still it's getting messy in some places. The code ...
3
votes
1answer
86 views
Quicksort using pointers
As an exercise, I've written quicksort algorithm in C using pointers. Please comment and help me find the cases where it breaks (if any).
void qsort(int *, int, int);
void swap(int *, int *);
void ...
0
votes
1answer
50 views
Box(x,y,X,Y), box(x,X,y,Y), box(x,w,y,h), box(x,y,w,h) or box(fromPos,toPos)? [closed]
Say you are representing a box, or creating a function that slices a 2d array, or whatever. How do you represent it?
2
votes
1answer
91 views
Can I make a regex array to iterate through in C++?
I have to check a string to various regular expressions in C++. Up to now, I've done this using something similar to this:
regex regex_a (".."); string rewrite_a = "($1/$2)";
regex regex_b (".."); ...
2
votes
1answer
115 views
XML to Windows.Forms.Keys List
It took me a lot of poking around and unit testing to get the code to look like it is right now. So I have a XML file which in part looks like this
<FunctionKeys>
...
0
votes
2answers
63 views
A pattern to destructively extract items from an array
I want to efficiently (few intermediate objects) and neatly (few lines and easy to read) filter an array, removing and returning rejected items. So like a call to delete_if except instead of returning ...
1
vote
2answers
51 views
Best way to check for one of two values in an array in PHP
I want to see if one of two values (a, b) are in an array. Here's my current thought:
$match_array = array('a','b');
$array_under_test = array('b', 'd', 'f');
if (array_intersect($match_array, ...
1
vote
1answer
86 views
High School Java Class: Pong Project External Reviewer
Panelball class:
import java.awt.*;
import java.awt.event.KeyEvent;
import javax.swing.*;
public class Panelball extends JPanel implements Runnable {
private static final long ...
3
votes
2answers
199 views
Optimizing unboxed array operations in Haskell
Consider this simplified code which successively permutes array elements:
import Data.Word
import Data.Bits
import Data.Array.Unboxed
import Data.Array.Base
import Data.Array.ST
test3 :: UArray Int ...
2
votes
1answer
80 views
Most efficient way to insert into ordered sequence
I have a dashboard like interface, that can have many tabs. There can be as many or as few tabs as the user likes, with the user being allowed to re order them as they wish. Exactly like browsers do.
...
1
vote
1answer
59 views
Referring to nested arrays and array_merge (php)
In such an array:
$arr = Array (
[key0] => Array (
[subkey0] => Array (
[0] => "value0"
[1] => "value1"
)
[subkey1] => Array (
...
3
votes
1answer
214 views
Calculating n x n determinant
According to instructions and sample code from MSDN Magazine and comments from post here determinant of n x n...
I changed code to be like this:
using System;
internal class ...
0
votes
3answers
77 views
Review: Compare two Anagrams words in C
A simple attempt by me to test whether two words are anagrams or not. Here is the code:
#include <stdio.h>
#include <ctype.h>
#define CH_LEN 15
#define N 26
int main(void) {
char ...
2
votes
1answer
607 views
Snake game — made with Python
I wrote a simple Python snake game, it's about 250 lines of code. Can someone give me some advice on how to refactor/make it better?
game.py
# game.py - 3/22/2013
import pygame, sys, os
from ...
0
votes
1answer
96 views
Turning multiple PHP arrays into one array ready for conversion to Javascript
I am creating a multiple choice quiz game with PHP and Javascript. Questions can have 2 to 6 answers. I have been using the PHP queries in the code below to get arrays of the questions of a quiz, and ...
0
votes
2answers
101 views
Checking for array key exists in multi-dimensional array in PHP
Say I have a data structure like this:
array(3) {
["id"]=>
int(1)
["name"]=>
string(3) "foo"
["message"]=>
array(1) {
["action"]=>
string(3) "PUT"
}
}
Where ...
1
vote
1answer
52 views
Help creating a workable design?
I received the following feedback for my code:
"I still do not see a design here that will work.
It is a very bad idea to have the big switch and loop at this point. All you need in your main() ...
1
vote
1answer
150 views
PHP generic array group by using lambda
K.I.S.S
But how about some error and misuse control? I am wishing it were .NET HAHA.
<?php
function array_group_by($arr, $key_selector) {
$result = array();
foreach($arr as $i){
...
1
vote
2answers
148 views
Random Sentences code review
This program use random number generator to create sentences. It prints 20 sentences randomly.
Here is the code:
#include <stdio.h>
#include <string.h>
#include <time.h>
#include ...
0
votes
1answer
62 views
2D Array: Retrieve the “Left” Item
I am creating a game that contains a Board and Pieces. The Board is basically a 2D array of Pieces. [Think smaller chess board]
One of the things that I want to accomplish is to be able to retrieve ...
3
votes
1answer
221 views
Better Javascript to find unique values in an array
My objective is to make an array of unique keys from a list of objects. Example:
Input:
var input = [{"a":1, "b":2}, {"a":3, "c":4}, {"a":5}]
Output:
[ "a", "b", "c" ]
Current approach:
var ...
2
votes
1answer
119 views
Too slow two strings comparer
I have 2 strings for example:
abcabc and bcabca
or
aaaabb and abaaba
I checked that second string is the same or not like first string but shifted.
bcabca = ..abca + bc...
Here is code it works ...
5
votes
2answers
148 views
Array find min value with user-defined comparison compare function
My user defined comparison compare function is defined with an array:
$boardkey_to_values=Array(19=>2601248,23=>2601248,39=>2603445,
...