An array is a systematic arrangement of similar objects, usually in rows and columns.

learn more… | top users | synonyms

-3
votes
2answers
80 views

Why use pointer to array of strings in C

static const char *action_prompt[] = { "Do you want to list the directory %s (y/n): ", "Do you want to execute %s (y/n): ", "Do you want to list the file %s (y/n): " }; Why is ...
-2
votes
4answers
124 views

how to speed the random access of 2D array? [on hold]

arr[2^30][100000] for (int i = 0; i < 2^28; i++) { value = a*b+c;//only a example. In all, value is an integer. arr[value][arr[value].length++] = i; } My code like above. Random access a ...
0
votes
1answer
48 views

find longest subsequence with sum less than or equal to k

I have a vector<int> num, I want to get the size of longest subarray with the sum less than or equal to k. My approach: O(n^2). Repeat for every element in the array. Can we do better?' ...
0
votes
0answers
37 views

Array in Hexadecimal in Assembly x86 MASM [migrated]

If: (I believe the registers are adjacent to one another...) A BYTE 0xB, 0d20, 0d10, 0d13, 0x0C B WORD 0d30, 0d40, 0d70, 0hB D DWORD 0xB0, 0x200, 0x310, 0x400, 0x500, 0x600 Then: What is [A+2]?...
-1
votes
1answer
23 views

Creating block of data from a large input data

I am working on an algorithm whose specs says that it accepts 32 bit input (long type). My actual data is 14 bytes e.g 11:12:12:04:DD I have created sub arrays like subarray1[4]={'1','1',':',1} // ...
1
vote
3answers
259 views

Find if any pair exists in an unsorted array?

I have come across a programming question in which I have to determine : Does there exists at least one pair in a given unsorted array such that |i - j| <= K and |A[i] - A[j]| <= x ? ...
-1
votes
1answer
42 views

How to fit k-length arrays to number of bigger arrays?

I have n number of one-dimensional arrays similar to: [0,0,0,0,0,1,1,1,0,0,1,1,...] 0's and 1's indicating occupation. And k number of smaller arrays similar to: [2,2,2], [2,2], [2], [2,2,2,2] ...
-2
votes
1answer
62 views

How to ask a user how many inputs they want

I want to know if it possible to use arrays for a more viable alternative of getting a non-predetermined number of inputs as an array and with an indefinite number of inputs. (python) original code --...
0
votes
2answers
77 views

Example of problem caused by casting Object[] to E[]

I've heard here and there that arrays contain runtime data about their type, making you unable to instantiate an E[] (E being a generic type parameter, for example in a class Foo<E>), and that ...
0
votes
1answer
89 views

Is there anyway I can store the static std::vectors of pointers of all my derived classes in my base class?

I currently have a program that has multiple derived classes. All instances of a derived class are stored inside of that class's static vector of pointers. I also have a static vector of pointers ...
3
votes
2answers
150 views

Is it good practice to use array.pop() assignment in a while loop condition?

Just saw a code snippet that used an array pop assignment in the while condition; was wondering if this is acceptable/good practice? var arr = [0,1,2,3,4,5]; var current; while (current = arr.pop()) {...
1
vote
2answers
126 views

Having trouble with AP computer science sample test problem

I am currently taking AP Computer Science at my high school and while looking at some sample AP test problems I came across one that really confused me. Sample Problem The answer to the problem is ...
1
vote
4answers
58 views

Chunking an array into letter groups that are generally equal length

Given a list of items, I want to break it up into four groups with as equal length as possible. The items need to stay grouped by the first letter in each item as well. 26 letters / 4 groups would ...
0
votes
1answer
118 views

Algorithm to find the highest Tetromino in a Tetris board?

Lets say that our Tetris board is represented as a 2D array of zeros and ones, where a 0 means empty and 1 means occupied, and you where asked to find the highest row in which a tetromino exists. ...
1
vote
4answers
174 views

immutable string in array, reference type vs value type

Trying to understand strings better in C# Are these assertions correct? string is immutable string is reference type but behaves like value type For these code samples... string x = "one" (...
-5
votes
3answers
181 views

Char array - why do we need +1 byte for sentinel value?

Can anyone explain why do we need +1 byte for sentinel value? As we know that 1 char = 1 byte so if we declare an array such as char a[50] why I can't store 50 chars instead of 49?
1
vote
0answers
136 views

.Net speed vs Custom Code speed

In an int?[] garunteed to have original values, I wanted to find the index of null, which will only be a single index. I drilled into the Array.IndexOf(T[] array, T value) .NET and, after all of the ...
3
votes
1answer
172 views

Is it considered a bad practice to oversize an array so that negative indices behave well?

I have been practicing implementing some classic dynamic programming algorithms and was wondering if my implementation of the longest common subsequence search has a significant code smell. In python,...
0
votes
1answer
53 views

reordering sorted array to level-order array without queue

I have very large sorted array, stored on the disk. I can random access any element. I want to make it level-ordered in order to speed up binary search there. The idea is borrowed from: http://...
1
vote
0answers
81 views

Given a two-dimensional array what is there a good way to identify distinct regions of elements?

I am generating a 2D "world map" in Unity which I use C# and Perlin noise for. I have a Tile object that holds the graphic of the tile and position. There are a few more attributes to this class, ...
-1
votes
1answer
50 views

Using a variable to define counter limits in a FOR…NEXT loop

I'm using Excel VBA to manipulate a one-dimensional array with approximately 100,000 numerical elements. I am seeing huge performance differences between the following 2 methods: method(1) k1 = 10 ...
2
votes
5answers
533 views

Why isn't byte | bit the only built in data type?

All languages I have seen so far have multiple builtin data types (int, double, float, char, long...). But if we look closely, they are just arbitrary arrays of bits, the only difference between them ...
0
votes
1answer
95 views

Reference variable concept (Java)

I'm working my way (slowly, but surely) through a book: Introduction to Java Programming, 10th edition, Comprehensive, by J. Liang (ISBN10: 0133761312) It explains the idea of a reference variable ...
4
votes
5answers
349 views

How are mixed, sizeless lists implemented in higher level languages?

Most higher level (or scripting) languages out there have data structures that can hold different types of data (like numbers, strings and even functions) in the same structure, and you can also add ...
0
votes
1answer
49 views

Removing constraints of Java array

Java arrays only allow subscripts to range between 0 and N-1 for an array of size N. The class below aims to remove that constraint by allowing the class user to specify the valid subscripts ...
-3
votes
2answers
77 views

ArrayList Dynamic remove and add for socker client [closed]

I have one ArrayList in Java and a save the socket and one unique id. When someone client is add in the ArrayList, the unique id i have is NOT the same with position in ArrayList. When someone ...
0
votes
0answers
62 views

Converting a 1D character array to a 2D array in random order.

I define my character array (9 items) as the following: char arr[] = {'a', 'c', 'b', 'z', 'k', 'l', 'j', 'o', 'd'} From this array, I would like to create a 3x3 array, in which the characters are in ...
2
votes
3answers
208 views

Why are arrays often treated as second-class citizens?

In many programming languages, arrays don't get as much attention as other data structures. In Java, there is no Array<T> type collection to make arrays feel more consistent, such as in ...
6
votes
3answers
152 views

What is the origin of counting from zero in programming languages?

This is a question which I have wondered (and been asked) about for a long time. In (most? all?) programming languages, an index begins at zero for an array, string, etc. I recognize it became ...
-1
votes
1answer
136 views

What is the proper or recommended way to save String[]'s, Array's, ArrayList's and int[]'s to Android?

I've looked up this question many many times but keep seeing different answers, what is the BEST way to save array's? It seems ludicrously infantile that there is no standard or easy way to save ...
1
vote
1answer
35 views

How to map collection of unique large numbers to an array?

I have a list of unique 8 byte random ids and new ids are generated often. Let's say that the total number of ids can become at most N (let's say 100,000). Now, I want to map each of these ids to a ...
1
vote
4answers
295 views

Readability & Performance: Is it better to allow the Java garbage collector to clear a datastructure?

I work with large HashMap's and ArrayLists. When not needing them to be in memory any longer, I use myArray.clear(); to free up the memory. When my colleague saw that line, he changed it to myArray ...
-1
votes
1answer
84 views

Should I add 1 to my unknown string size when I create a char array to hold it via malloc? [closed]

When I have a string of unknown size and I create an char array to hold this string. I do something like this: #define LINE_END "\r\n" int line_end_size = strlen(LINE_END); char line[]="Hello! ...
-3
votes
1answer
136 views

Using System.out.println() with loops and arrays [closed]

Is there anyway I can create a loop for System.out.println("...") and reading in the values? For example I wish to do this: System.out.println("Input the Executive's name: "); String eName = ...
0
votes
0answers
132 views

Realizing pagination for merged array from multiple data sources (APIs)

I'm improving a WordPress theme with PHP. The theme contains a gallery section which loads data from the Flickr API. Now the client wants to display Flickr galleries as well as "local" galleries ...
-3
votes
1answer
121 views

How to compare and replace value from two object inside array?

Here i want to replace price in data1 to price from data2, and it updated if the id is same. Is it possible to do that without nested loop? var data1 = [{ "id": "56e641d4864e5b780bb992c6", ...
1
vote
1answer
92 views

How to combine N non-comparable arrays up to an output limit in a fair way?

Given N non-comparable arrays of different sizes, what is the best method to combine them into one output array? Since the input arrays are non-comparable, a metric is needed to represent how ...
1
vote
4answers
76 views

Obtaining lists from an array

Let's say my array contains integers. I'd like to create lists, so that every list contains indexes where a particular value occured in the array. For instance, if the array was 5,0,3,5,2,5,3, we ...
1
vote
0answers
110 views

Why my greedy algorithm not working for merge stone problem

Merge Stone Problem: You have n piles of stones in a line. For example, [4, 1, 2] means 3 piles of stone, the first pile has 4 stones, the second pile has 1 stone, and so on. You task is to merge ...
0
votes
1answer
138 views

Is there ever a reason to use variable variables in PHP rather than an array? [closed]

Is there any situation where an array is not suitable but a variable variable is? I cannot think of one or find one on any Stack Programmer Q&A. <?php $foo = array(); for($i = 0;$i < 3; $i+...
0
votes
1answer
138 views

How to save tuplas values, to later search on it

Scenario I have some values of the type : (Name - Email) From this couples of data, I have to set a ArrayList of "Name" values,something like: |Name1|Name2| --- |NameN| to set a Spinner. (Ordered ...
2
votes
2answers
281 views

Merge sort and O(n log n) mystery

I read every explanation here but still not convinced. I think mergesort is n * n and I know I am wrong but not sure where. Here is what I think: Suppose we are sorting 8 elements and this is the ...
-1
votes
1answer
67 views

(Multidimensional array in C) How to make my output in a vertical position rather than in horizontal when the size of the array is n[3][4] [closed]

I would like to have some help. I must find a way that the output must be: A B C 90 60 80 50 100 70 100 20 100 10 50 75 Because the previous output is: A 90 50 100 10 B 60 100 ...
6
votes
3answers
307 views

How to store ordered information in a Relational Database

I am trying to understand how to properly store ordered information in a relational database. An example: Say I have a Playlist, consisting of Songs. Inside my Relational Database, I have a table of ...
4
votes
1answer
336 views

Why is Array.prototype designed to be a fully functional array?

In the below visualisation, There are two array objects(cars & bikes) that are created with below syntax, var cars = new Array("Saab", "Volvo", "BMW"); var bikes = ["Honda", "Yamaha"]; whose [[...
-1
votes
1answer
178 views

eradicating the array = loop mindset [closed]

I have noticed a common issue in code reviews, that takes this form: // "arr" is an array for (i = 0; i < arr.length; ++i) { if (i == 3) { // do something with arr[i] } if (i ==...
15
votes
1answer
5k views

PHP: when to use arrays, and when to use objects for mostly-data-storing code constructs?

PHP is a mixed paradigm language, allowing to use and return non-object data types, such as arrays. I pose a question to try to clarify some guidelines for selection of arrays vs objects when deciding ...
-1
votes
2answers
248 views

3D array updating in C# [closed]

I'm curious because I have read that once an array is declared it can not be changed. Maybe if I lay out my thoughts. Say, I have a cube with dimensions 5x5x5 and I have a viewport that can rotate ...
23
votes
5answers
14k views

What's the use of .Any() in a C# List<>?

I've been discussing this with colleagues, and we couldn't figure out what the use is of .Any for any given List<>, in C#. You can check the validity of an element in the array like the ...
2
votes
3answers
470 views

Is it a good idea to modify the array keys in foreach

Some times I need to modify an array key for example something like: $temp = array(); foreach($arrayIWantToModify as $key => $value) { if($value % 2) == 0) { $temp['odd_' . $key] = $...