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

2
votes
1answer
33 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
24 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
48 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
votes
0answers
30 views

Array sorting code and file IO [closed]

I would appreciate if someone could help me finalise a code. I need to read in people's info (such as ID, age, etc.) from a text file into different arrays. Records are like this 2012317109 Jamie ...
1
vote
2answers
39 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
60 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
99 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
74 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
38 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
54 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
79 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
69 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
159 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
52 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
44 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
50 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
47 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
127 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
42 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
66 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
109 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
94 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
63 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
161 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
239 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
65 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
124 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
97 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
1answer
206 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
44 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
105 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 ...
2
votes
3answers
111 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
111 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
124 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
vote
0answers
28 views

NSArray and NSNumber-int conversions

I have a textView which is displaying a string. I also have an array which keeps track of where every line begins, it stores the "start index" or NSRange.location for every line. However, when text ...
0
votes
3answers
98 views

Given an 2D array which is row and column wise sorted. What is the efficient way to search for an element?

For example, given a 2D array (a matrix) {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}} What are the solutions to find a number? say 6. Here's the code I tried using Binary search method - (code ...
3
votes
4answers
225 views

How make array search more efficient in python?

Here is Python code written to perform the following operations: Find each occurrence of a three-letter sequence in a character array (e.g. a sequence such as ('a','b','c')), including overlapping ...
1
vote
1answer
102 views

Multiple jQuery events on one element with different functions and target selectors

According to this two questions: [1] and [2] I need a way to combine these two methods of handling the event attachment in jQuery. $('selector').on({ mouseenter: function() {}, mouseleave: ...
2
votes
1answer
186 views

Ranking and sorting on Array/List

My apology, I am quite new to posting a question in this forum. I had a task where I was supposed to write a solution to sort entries(Name, score - in an array/list) in order of score and generate ...
0
votes
1answer
68 views

Optimize nested enumerate blocks?

Well, i have 3 nested NSEnumeration loops, used to get the textfields of a custom cell, in a custom table in a custom view in a controller... How can i change this code to make more readable and more ...
0
votes
1answer
177 views

Best way convert byte array to hex string in C#

I want to find a prettier version of this method: public static string ByteArrayToString(byte[] byteArray) { var hex = new StringBuilder(byteArray.Length * 2); foreach (var b in byteArray) ...
4
votes
2answers
101 views

Counting letters program. Notation and optimisation help

I am writing a program in C running on UNIX which counts the number of each letters in a input text file. For a file like this: The cat sat on the green mat The output would be like this: The ...
0
votes
1answer
62 views

JSON get Array in Array [closed]

I need to generate JSON array in array data. I am able to get data from first array, however not able to get data from child array. For example :- [ { "id":"2012" "month": [ { ...
1
vote
0answers
166 views

App engine Java: Sum difference two arrays - How to improve performance?

I have a function in App Engine java where I compare two patterns stored in an int array. Below is the code: public static int patternMatch(int [] pattern1, int [] pattern2, int range) { int ...
1
vote
2answers
180 views

Please help me debug this little C program on dynamic two-dimensional array?

I am a newbie here. I have written a little C program, which is to create a two-dimensional matrix. Here is the code: #include <stdio.h> #include <stdlib.h> int **CreatMatrix(int ...
1
vote
1answer
116 views

C arrays and loops optimization

I am writing a program for learning purposes that takes an input of a file structured similarly to: 13,22,13,14,31,22, 3, 1,12,10 11, 4,23, 7, 5, 1, 9,33,11,10 40,19,17,23, 2,43,35,21, 4,34 ...
4
votes
1answer
134 views

Optimizing Python / Numpy Code

So I'm implementing a version of the mean shift image processing algorithm for color segmentation in python/numpy. I've written a pure numpy version of the actual mean shifting per pixel (which I ...
0
votes
1answer
63 views

help review array of object code [closed]

public class DoubleMatrix { private double[][] doubMatrix; public DoubleMatrix(int row, int col) { if(row > 0 && col > 0) { makeDoubMatrix(row,col); } ...
1
vote
2answers
63 views

Request for help to tidy up code involving arrays and loops

I posted the following code on here a few days ago: public class Practical4_Assessed { public static void main(String[] args) { Random numberGenerator = new Random(); int[] ...
0
votes
2answers
71 views

add Matrix method review

package homework3; public class DoubleMatrix { private double[][] doubMatrix; public DoubleMatrix() { int row; int col; if(row > 0 && col > 0) ...

1 2 3