The array tag has no wiki summary.
2
votes
1answer
91 views
Improving the running time of Breadth First Search and Adjacency List creation
We are given an array of integers where all elements are between 0-9. have to start from the 1st position and reach end in minimum no of moves such that we can from an index i move 1 position back and ...
-5
votes
0answers
51 views
Java: What does the following method do? [migrated]
public static void main(String[] args)
{
String[] months = ("jan","Feb", "March", "April", .... , "Dec");
System.out.println(months[Integer.parseInt(args[0]-1)]);
}
Why args[0]-1 ?
0
votes
0answers
18 views
Length of array (C) [migrated]
I have an array of 10 elements. This array stocks some informations but last information is ended by an symbol "END" (which is -1).
for exemple:
array[0] = 1;
array[1] = 1;
array[2] = 1;
array[3] = ...
3
votes
2answers
174 views
Data structure for grid with negative indeces
Sorry if this is an insultingly obvious concept, but it's something I haven't done before and I've been unable to find any material discussing the best way to approach it.
I'm wondering what's the ...
1
vote
1answer
100 views
How to construct a cubie representation of a rubik's cube, given an array
Just to get this out of the way, I have seen this, and it is not what I'm looking for.
So, let's say you are programming a Rubik's Cube. (I know, very unoriginal, but bored programmers have to do ...
4
votes
4answers
515 views
Why do arrays in Java not override equals()?
I was working with a HashSet the other day, which has this written in the spec:
[add()] adds the specified element e to this set if this set contains no element e2 such that (e==null ? e2==null : ...
2
votes
1answer
222 views
Why does Java support brackets behind variables and even behind method signatures? [closed]
Java allows this:
class X{
int i,j[]; // j is an array, i is not
}
and even worse, it allows this:
class X{
int foo(String bar)[][][] // foo actually returns int[][][]
{ return null; } ...
0
votes
0answers
32 views
Search substring using suffix array (and LCP)
I'm searching for a best way to improve suffix array run time using LCP.
My text (about 2 500 000 chars) seems like: 0ricco0eric0america0polo0....
My thoughs:
SA=suffixArray
char=firstChar(input)
s ...
5
votes
1answer
160 views
At ping, why do we have to do array copying instead of passing on the source array that the client sent to us?
So I have been googling about this OpenSSL heart-bleed thing and somehow sees that it is caused by the heartbeat extension which requires client to ping the server to show its aliveness and it all ...
2
votes
1answer
98 views
Accessing a private array when I have an extension method
I'm trying to make a number of data classes for my C#/XNA game, which would essentially be a wrapper around T[,]:
public interface IGrid<T>
where T : struct
{
Point Size { get; }
T ...
0
votes
1answer
302 views
Is a PHP array an example of a dynamic data structure?
I did my homework, and it says that dynamic data structures are "data structures that change in size as a program needs it to by allocating and de-allocating memory from the heap".
So I was ...
1
vote
1answer
92 views
If a variable containing a function gave the function's return instead of a reference to the function, what would an array of functions return? [closed]
I'm creating a prototype scripting language similar to something like Javascript. In my language, every single reference to a variable is actually a function call (a getter function), whether it has ...
1
vote
3answers
285 views
Choice between 1-dimensional and 2-dimensional array
I'm implementing the Chessboard class to represent the chessboard. I've to implement the transformations (reflections and rotations) on the chess board possible.
The possible transformations includes ...
0
votes
3answers
145 views
Sorting an array when values are decreased by each swap [closed]
Recently in an interview I come across a question:
We have an unsorted array, we need to sort it with minimum number of swap. We have in sort a 'tax' of 1 is deducted from the number we are ...
-1
votes
1answer
90 views
Fortran 90 - How to create a coordinate system
So I need to code a simple program, and I need to define 2D coordinates?
Is there any coordinate system I can use in Fortran?
I was told it might have to be all in arrays? And if so, can anybody ...
0
votes
2answers
259 views
Quick algorithm to find matches between two arrays
I'm faced with the following problem:
I have an array which is produced by the parsing of a yaml file which contains patterns in the following structure.
"Programming books"
Title:
a ...
2
votes
3answers
450 views
How do you read this line of code?
Forgive me for my poor English, me and my friend were doing school homework, suddenly he asked me to read this line of code ptr = &array[1][1][1] (ptr is a pointer to an integer).
He said
...
4
votes
2answers
4k views
Should I use a list or an array?
I'm working on a windows form to calculate UPC for item numbers.
I successfully create one that will handle one item number/UPC at a time, now I want to expand and do it for multiple item ...
0
votes
1answer
77 views
What is a cross-platform way to expose an Array[][] over a webservice? Any JSON nuances to be aware of?
I need to expose an Array[][] to many different clients (iPhone, Android, PC, Unix, etc), and need to make it available over HTTP/s
This brings me to JSON, and makes me wonder how do all the other ...
0
votes
2answers
288 views
PHP SplFixedArray How To Deal With billions of indexes?
I've built a flatfile db system that will work like mini-noSQL system
and it split db to smaller files, and I did a SplFixedArray wrapper for it
with a method for searching usage built on preg_grep.
...
1
vote
3answers
486 views
Arrays vs Objects in view template
I am wondering, in view templates, what would contribute to me choosing between using arrays or objects for getting things printed out in arrays
{{$user->zip_code}} vs {{$user['zip_code']}}
I'm ...
1
vote
4answers
230 views
Is it considered bad practice to access a returned array by a key straight away?
I couldn't think of a good way to word the title, sorry. But what I mean is, is it considered bad practice to do:
print get_array()[2]
over:
output=get_array()
print output[2]
(where get_array() ...
-1
votes
3answers
518 views
Find all lines segments intersections
I have a collection of lines segments, represented by an array.
Ex: [3,7,13,6,9] is 4 line segments: [(3,7)(7,13)] , [(7,13)(13,6)] , [(13,6)(6,9)] , ([6,9)(9,3)]
I want to find all the lines ...
-1
votes
5answers
1k views
Reverse subarray of an array with O(1)
I have an idea how to implement sub array reverse with O(1), not including precalculation such as reading the input. I will have many reverse operations, and I can't use the trivial solution of O(N).
...
3
votes
2answers
168 views
What would be the optimal way to solve a problem like this?
I have a problem where I have to change all the Xs in a 2D array into 0s, and I have to calculate the minimum steps (where a single step consists of changing an entire row or column) required to do ...
2
votes
3answers
239 views
What language has integrated “list insertion” as part of code *syntax*?
Many programming languages permit natural manipulation of strings, and some languages permit the manipulations of lists too.
More often then not (always?), these operations are done as procedure ...
2
votes
6answers
353 views
Settle an Argument: String vs. Array?
True or False: A string is the same thing as an array.
I had an interview the other day and the above question was asked. I said false, but the interviewer said it was actually true. I explained to ...
0
votes
1answer
362 views
Use ruby's array sort() method, or add items in correct place with a binary lookup?
If I am loading a whole load of items (un-ordered words from a file or something) would it be more efficient to load them all to a Ruby array, and then use the built in sort! method or to do a binary ...
0
votes
1answer
284 views
Sort rectangles in a grid based on a comparison of the center point of each
If I have a grid of rectangles and I move one of the rectangles, say above and to the left of another rectangle, how would I resort the rectangles?
Note the rectangles are in an array, so each ...
3
votes
2answers
573 views
CA1819: Properties should not return arrays. Does this happen only with arrays? If yes, why?
I have a question about CA1819 msdn performance warning.
The rule is: Arrays returned by properties are not write-protected, even if the property is read-only. To keep the array tamper-proof, the ...
2
votes
3answers
988 views
Specific reasons to create own array class over using std::array?
What specific conditions or requirements should you create your own array over using std::array?
Here is my background:
I'm developing a small simple library that a small group of people will use ...
2
votes
3answers
480 views
Best way to choose random element from weighted list
I want to create a simple game. Every so often, a power up should appear. Right now the different kinds of power ups are stored in an array.
However, not every power up should appear equally often: ...
1
vote
4answers
162 views
Efficient way of evaluating an array of strings then add to an array in Ruby
I am looking for an efficient way of evaluating an array of strings against a series of rules and then adding them to another array.
For example I have an array of strings:
something
a
1234
#gohere
...
-3
votes
2answers
1k views
Java: The best way to learn it when MOOCs and books are not enough? [closed]
This topic was taken from Stack Overflow, but it was put on-hold due to Opinion-based question. So I moved it to here.
I've had some great troubles with my homework exercises and I've used ...
1
vote
1answer
282 views
ruby-idiomatic hashes vs arrays
So I am still fairly new to ruby, though I have noticed that it is very hard to create 2d-array and that hashes seem to be more of the go to data structure than arrays.
I was wondering why the Ruby ...
1
vote
1answer
150 views
What is the name of this array transformation?
Start with an array of arrays; in this case, they are different lengths in order to demonstrate the technique, but they do not have to be.
[[1,2,3,4], [5,6,7], [8,9,10], [11,12,13,14,15]]
At the ...
4
votes
2answers
563 views
Array Multiplication and Division
I came across a question that (eventually) landed me wondering about array arithmetic. I'm thinking specifically in Ruby, but I think the concepts are language independent.
So, addition and ...
2
votes
1answer
109 views
Handling Dynamic amount of Strings for persistent and runtime storage in an IOS App
Background
I am dynamically building an FQL query statement and because of the nature of the app, I exclude FB family members, this is the base portion of the query and remains fairly static. The ...
0
votes
1answer
1k views
Sorting an ArrayList by a Split Value [closed]
I am attempting to create an list which should be sorted by a particular field in a colon separated string. I have an array of strings with the following values:
name1:535
name2:697
After sorting ...
4
votes
2answers
492 views
Implementing non-fixed length array support in a compiler
I'm thinking of building a language for PIC microcontrollers. I want to be able to use non-fixed size arrays, like this:
Declare the variable as int[]
Wait for input from serial connection
Make the ...
3
votes
4answers
1k views
Retrieving maximum value from a range in unsorted array
I have an unsorted array. I have queries in which I give a range and then the maximum value from that range has to returned.
For example:
array[]={23,17,9,45,78,2,4,6,90,1};
query(both inclusive): 2 ...
2
votes
4answers
1k views
How do you find the first common element in two arrays
The way I did it was to loop through each at the same time and add the current value to a separate set for each of the lists. Also, check if the current element is already in the other list's set. I ...
-4
votes
1answer
744 views
Program to verify all words in a crossword puzzle are valid
I have my own solution and wanted to check it against something online but couldn't find any examples. How would you solve this one. (I can post my code if necessary). I just want to see if someone ...
5
votes
2answers
307 views
Which design pattern is illustrated by inheriting IStructuralComparable interface?
We know that some design patterns are found so useful that they become features of the language itself.
For instance, the interface IEnumerator which is implemented by Array object.
This helps in ...
0
votes
3answers
460 views
A simple algorithm for finding duplicate floats [closed]
We have N numbers(real numbers(float)).They can be positive or negative or anything we do not know except the fact that there is exactly one number which has a duplicate and the rest all are distinct. ...
3
votes
1answer
639 views
The array class in C# - Implementation questions
I am studying the Array class in C#. The following is the implementation of System.Array class:
[SerializableAttribute]
[ComVisibleAttribute(true)]
public abstract class Array : ICloneable, IList, ...
0
votes
3answers
276 views
Count true array elements
In my code (Python+numpy or Matlab, but issue can apply to any array programming language), I often need to count the number of elements in an array where the elements are true. Usually, I implement ...
5
votes
5answers
566 views
What's the effect of this assignment (whatever the language)?
I think my book (Programming Languages: Principles and Paradigms) is wrong. a is a vector, assume a C-like language:
b = 0;
a[f(3)] = a[f(3)] + 1;
int f(int n) {
if(b == 0) {
b = 1;
...
4
votes
4answers
32k views
Initializing char array with string
I don't remember how I got to the thread, but I was reading its replies and one of them states that you should never initialize a char[] with a string literal.
My question: Is initializing a ...
0
votes
6answers
848 views
Visualization of N>2-D array? [closed]
I have an array of dimension 5. But, I can't figure out how to visualize that array?
int[][][][][] array = new int[4][4][4][6][2].
Is there a good way to visualize arrays with dimension counts of 3 ...