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
19 views

Painting Tom Sawyer's Fence - programming on Free Pascal

Tom Sawyer has many friends who paints his fence. Each friend painted contiguous part of the fence. Some planks could stay unpainted, some could be painted several times. Program must output the ...
2
votes
0answers
29 views

Fastest way to iterate over Numpy array

I wrote a function to calculate the gamma coefficient of a clustering. The bottleneck is the comparison of values from dist_withing to dist_between. To speed this up, I tried to adapt and compile it ...
0
votes
0answers
12 views

Program stops working, pointer error i'm sure [migrated]

I have this program, and I'm still getting used to C++ pointers, so It's probably an issue with that. But I am having the program crash when the getStructData() function is called. I've probably ...
4
votes
1answer
73 views

A boolean expression parser, written in Java

I was trying to write some of the Haskell list functions into Java, and I realized that one of the key strengths for many of the functions was the ability to pass in a boolean expression. I decided to ...
0
votes
1answer
38 views

How to put a lot of information in the class?

I have such a problem: I'm parsing a lot of HTML files with Simple HTML DOM Parser, that's why I need to use three foreachs to parse the necessary information from it -> I am getting a lot of ...
3
votes
1answer
59 views

Optimising Funny Marbles

Problem statement is at http://www.codechef.com/DEC13/problems/MARBLEGF Lira is given array A, which contains elements between 1000 and 2000. Three types of queries can be performed on this ...
4
votes
2answers
76 views

Splitting a text file into paragraphs and words

I'm iterating through a number of text files, trying to locate all carriage-returns, and individually save the text between carriage-returns. I get the index numbers of all carriage-returns, but I ...
1
vote
1answer
45 views

Copying a lot of code to filter four PHP arrays

I have made this search filter and it works fine, but I think the code looks a little messy and I have no idea how to clean it up. I hope the following makes sense, otherwise please tell me which ...
3
votes
1answer
37 views

Clone array elements when multiplying by a scalar

Update: Way to bury the lead. ;) The main question here is how best to make sure each array element is a separate string instance. I am building an array of strings to form the "empty" ...
1
vote
1answer
38 views

Reading Multidimensional arrays

I am building a cypher program which uses a matrix of numbers and letters. A message is encoded according to the row an collum each letter of the message is found in the matrix. I am trying to find a ...
8
votes
4answers
174 views

Finding all indices of largest value in an array

I have the following code that gives me the indices of an array's largest value: public static void main(String[] args) { float[] elementList = new float[7]; elementList[0] = 8F; ...
2
votes
3answers
76 views

Make code more memory efficient, or shorter

//rename files if(!empty($_FILES[$desktop_fieldname_1280x800]['name'])){ file_exists($desktop_filename_1280x800 = mb_strtolower($desktop_dir_1280x800 . 'wall_desktop_1280x800_' ...
1
vote
1answer
36 views

TCPDUMP file (part of a real capture)

I have been working on this code for quite a while and just want to make sure it is up to good standards. I know many of you will have questions, so as they come up, I will edit my initial question to ...
3
votes
3answers
67 views

Sorting strings in a one dimensional array

What are the better solutions possible? I have a character array with different strings. There is a max size for the strings. In case a string is smaller than max size remaining places are filled ...
3
votes
1answer
72 views

Optimising Lucky Number Program

In this, we are given an array of numbers, say 1 2 3 4. We start from a given position, let's say the 1st position. We cancel that number and move forward that many non-cancelled numbers. The number ...
1
vote
1answer
42 views

Pushing instantiated class in an array

I've just stumbled upon something today that seemed "unethical" in PHP. What I originally thought as malpractice, turned out to work just fine. Basically what I was wondering is if pushing an ...
1
vote
0answers
24 views

Take an array and return “n” elements, as evenly spaced as possible

I get the following correct results from this code, but it seems incredibly clunky to me. Is there anything I could be doing more elegantly? The results can be imprecise - as long as it's the right ...
5
votes
3answers
143 views

Find elements occurring even number of times in an integer array

I came across an interview question, which is like this: You have an array of integers, such that each integer is present an odd number of time, except 3 of them. Find the three numbers. I tried ...
0
votes
1answer
54 views

Copying Dictionary collection into an array [closed]

Hi I want to minimize the following code: private string getAllCommandLineOptionsAsString() { string s = ""; var cmdOptionsList = commandOptionDictionary.ToList(); foreach (var cmdOptions in ...
1
vote
2answers
110 views

Which PHP code is faster?

Time is very important from times immemorial. Doing great things and making it happen in less time is more important as it can mean less effort. So I really like to know which way is faster and more ...
5
votes
2answers
128 views

Simplification of byte array comparison algorithm

I have an algorithm that evaluates in input byte[] with a source byte[]. Several conditions can be encountered: Match found No match found End of input array End of source array Input wildcard (*) ...
2
votes
1answer
98 views

Read multidimensional array from file in C

I want to read multidimensional double array from file into a single pointer variable. The number of rows and columns are not known and need to be determined when reading the file in order to allocate ...
17
votes
6answers
938 views

How can I make this mess of Java for-loops faster?

I'm trying to find all the 3, 4, 5, and 6 letter words given 6 letters. I am finding them by comparing every combination of the 6 letters to an ArrayList of words called sortedDictionary. I have ...
4
votes
2answers
119 views

Why is this program for extracting IDs from a file so slow?

This is roughly what my data file looks like: # Monid U B V R I u g r i J Jerr H Herr K Kerr IRAC1 I1err ...
2
votes
1answer
98 views

Building an histogram array in PHP

I'm visualizing my stored data in an histogram similar to this one: However, I'm sure that my code smells a lot! So I'd like to have your opinion on how to make it better. Here's my current code: ...
4
votes
2answers
116 views

Binary search for inserting in array

I have written a method that uses binary search to insert a value into an array. It is working, but i would like to get a second opinion to see if i didn't write too much code for it. aka doing same ...
6
votes
1answer
125 views

Find all subsets of an int array whose sums equal a given target

I am trying to implement a function below: Given a target sum, populate all subsets, whose sum is equal to the target sum, from an int array. For example: Target sum is 15. An int array is { ...
2
votes
1answer
98 views

Find missing numbers in a range, when a sorted array with two elements with range repeat once

Suggestions for cleanup and optimization request. This question is a follow-up question on this post. Lets assume the range of 1, 2, 3, 4. This function takes in an array of repeated elements, ...
3
votes
1answer
122 views

Find two missing elements from a sorted array in given range

Looking for reviewers to suggest optimization and improvements, and to evaluate coding practices. final class Variables { private final int x; private final int y; Variables(int x2, int ...
3
votes
2answers
157 views

Implementing Array#uniq in Ruby

I've implemented a working version of Array#uniq in Ruby to answer the question here: http://www.rubeque.com/problems/like-a-snowflake, but I'd like to see if there's ways to clean up my code or some ...
2
votes
3answers
114 views

Clear ArrayList

I create class level static ArrayList by the following line. static ArrayList<Student> studentList = null; Then I create and fill ArrayList with some objects inside a function. studentList = ...
2
votes
2answers
119 views

Find a missing numbers, single missing number and two missing numbers, from consecutive range

Contains 3 options. Given an input array Unsorted and consecutive range, and array is 1 element short. eg: range is 6-9, and array = [7, 8, 9] output should be 6. All conditions same as previous ...
3
votes
5answers
154 views

count all array[index] == index occurrences

The method foo gets a sorted list with different numbers as a parameter and returns the count of all the occurrences such that: i == list[i] (where i is the index 0 <= i <= len(list)). def ...
2
votes
2answers
37 views

A menu option that receives input from users and then performs actions

Please review my FindMovie and AddMovie methods. public static boolean FindMovie(String movietofind, String[] ArrayMovie) { movie Movieobject = new movie(); for (String ArrayMovie1 : ...
6
votes
2answers
120 views

Generating a list of alternatively positioned odd and even number out of an array of unsorted integers

I had an half an hour interview with Microsoft for an intern position. I was asked to generate a list of alternatively positioned odd and even number out of an array of unsorted integers. I guess it ...
1
vote
4answers
108 views

A more efficient enqueue algorithm in Java

So I have this simple code in Java. It enqueue (adds) and element to the end of the queue (implemented by an ArrayList) without changing the original queue. public class MyQueue<T>{ private ...
4
votes
2answers
115 views

Please review my answer for interview question: merge two sorted arrays together

merge two sorted arrays together #include <iostream> #include <vector> std::vector<int> merge2Sorted ( std::vector<int> left, std::vector<int> right ) { //finger ...
4
votes
1answer
63 views

Is there a for-statement I can use to subtract elements in my 2-D in order to make my code more efficient and less-cumbersome?

This code works 100%, but I am trying to see if I can use a for-statement to make my second method less-cumbersome and more efficient instead of making so many variables. I have to show the ...
4
votes
1answer
134 views

Improving performance when sorting array of structs by multiple fields

I have an array of a struct containing 5 byte values. I need to sort this array by each value in a different order depending on the situation. These arrays are sometimes quite small (10-30 elements), ...
5
votes
1answer
191 views

How is my quarterly sales statistics program?

Am I making good use of a 2-D array? Is this code inefficient? I am supposed to receive input from 6 departments for 4 quarterly periods in Java. My assignment asks: Quarterly Sales Statistics ...
2
votes
2answers
78 views

Finding correct format? Arrays and Modulation

I am fairly new to programming and I am having difficulty modulating the following code. The program reads a file, selects certain requirements, and displays them. I have tried to use passing arrays ...
1
vote
2answers
140 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
42 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
57 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, ...
2
votes
2answers
56 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
400 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 ...
1
vote
1answer
106 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
196 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
102 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
800 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 ...