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

0
votes
1answer
31 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 ...
2
votes
0answers
110 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 ...
-1
votes
1answer
32 views

Bug in compiler Pelles, or my mistake? [closed]

I am using the latest version of the Pelles C IDE. I have noticed the following bug when i use a global array of structs: The struct has to have two members of any kind when you assing a value to ...
-2
votes
0answers
26 views

I have an array of strings and want to access each as a character array. How do I do this? [closed]

I have an array of strings and want to access each as a character array. How do I do this? I use the below commands to create the array of strings from a text file. // Open the file $fp = ...
2
votes
1answer
64 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
31 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
134 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
65 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
0answers
28 views

How do I find the length of the longest repeated number in the array of integers? [closed]

I have the code for counting each repeated number, and I know I have to store each count value into an array. But how would I do this? int length(int array[], int size) { int x; int count = 1; ...
2
votes
3answers
121 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
62 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 ...
1
vote
1answer
52 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
78 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. ...
2
votes
4answers
155 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
51 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
48 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)?

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
77 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
57 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
60 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
42 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
83 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
154 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
78 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
46 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 ( ...
0
votes
0answers
83 views

Bit array not working as fast as expected [closed]

I recently downloaded the bitarray module from here, for a faster prime sieve, but the results are dismal. from bitarray import bitarray from numpy import ones from timeit import timeit def ...
3
votes
1answer
156 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
74 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
358 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
67 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
57 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
84 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
145 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
60 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
116 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
112 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
124 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, ...
1
vote
2answers
73 views

Looking For a More Efficient/Elegant Way To Write a MySQL Query

I'm querying a MySQL database and displaying the info in order of timestamp (DESC). Essentially, I'm grabbing the last record in the database, displaying it's date and year as the header of it's ...
1
vote
3answers
217 views

Reverse a string without <string.h> header function

I'm learning C from K.N. King book and just arrive at a question to reverse the words in a sentence. Here is the output: Enter a sentence: you can cage a swallow can't you? Reversal of sentence: ...
0
votes
1answer
344 views

Please critique my C++ Deck class

I have recently finished creating my own Deck class for my Poker game. It works the way I want it to, but I would like to know if I can make it better and/or more efficient. Here's what I have: ...
3
votes
1answer
70 views

Matching element of arrays on a condition

if node[i] and node[i+1] are present in the neighbor[i], then store the 'i' position of node and print the 'i' value of node. this is also done by reversing the node array(only) and same type of ...
2
votes
2answers
152 views

Calculating and displaying number statistics

I'm writing a program which takes individual int inputs from the user and then outputs some details on the numbers (average, min, max and how many). Input.readInt() is a method I made which simply ...
3
votes
3answers
162 views

Most efficient way to iterate through arrays/can I use .times method in place of while method?

I created a quick program to test the precision of randomness generated by the .rand method. The primary question is whether I can use the .times method in place of the while code blocks to increase ...
3
votes
2answers
559 views

Magic Square in C (Beginner)

Still teaching myself C out of KN King's C Programming: Modern Approach. Actually pretty excited I go this problem solved in under 2 hours haha. I asked this over on Stack Overflow and it was ...
3
votes
1answer
46 views

Code to find the proper index comparing 3 values for max one

I have an algorithm and the idea is to move over an array choosing as index the index of the neighboring cell that has the max value. I.e. if array[i + 1][j + 1] has the largest value among the 3 ...
3
votes
1answer
133 views

Rails: Retrieve all parents, all possible children, sorted and with their “depth”

I have a model section with a column parent_id - the only thing identifying a parent/child relationship. I wrote a helper method to output all sections, all their possible subsections and include ...
3
votes
3answers
142 views

Searching item in array

I have a program that calculates some values and saves them to an array. Before save a value, program checks if there is already an identical value in array: string someData = GetData(); bool ...
3
votes
3answers
119 views

Cached empty collections

I often find myself in need to create empty collections. One of those days several years ago, I wrote something like the following to address that: public static class Array<T> { // As a ...
1
vote
1answer
276 views

first non-repeated character in a string in c

Write an efficient function to find the first non-repeated character in a string. For example, the first non-repeated character in "total" is 'o' and the first non-repeated character in "teeter" is ...

1 2 3