arrays

C#, a String's Split() method

C#, a String's Split() method, how can I put the resulting string[] into an ArrayList or Stack? ...

Copying lines from stdin to an array of character pointers

I would like to copy lines from stdin to an array of character pointers. For example if the user entered the following "the\nquick\nbrown\nfox" then I would like to have an array that looks like arr[0] = "the" arr[1] = "quick" arr[2] = "brown" arr[3] = "fox" Any pointers? ...

C# Looping through an array without throwing exception

Say i have an array of values: string[] text = new string[] {"val1", "val2", "val3", "val4", "val5"}; Then i have a basic loop: for(int i=0;i<=30;i++) { Console.WriteLine(i + " = " + text[i]) } Obviously this will cause an out of bounds exception, so what i want to do is when the counter reaches the upper bound of the array the...

How to assign values to the whole row of a dynamic two dimensional array?

I need to perform 9 different operations on a coordinate, depending on the position of the coordinate. I have a function that returns the coordinates of a position around the given coordinate (down, up, left, right or diagonals). The 9 different operations are the different possible 'types' of coordinate; if I'm dealing with coordinate (...

Flex Datagrid to Array?

Hello all, I need to convert a datagrid table in Adobe Flex to an ArrayCollection. I was expecting to be able to loop through each row of a datagrid and write that to the Array collection, but the only method for accessing data in the datagrid that I can find is SelectedItem, which doesn't help me. Obviously one could just copy the da...

Array of Matrices in MATLAB

Hello, I am looking for a way to store a large variable number of matrixes in an array in MATLAB. Are there any ways to achieve this? Example: for i: 1:unknown myArray(i) = zeros(500,800); end Where unknown is the varied length of the array, I can revise with additional info if needed. Update: Performance is the main reason I am...

What is the max key size for an array in PHP?

I am generating associative arrays and the key value is a string concat of 1..n columns. Is there a max length for keys that will come back to bite me? If so, I'll probably stop and do it differently. ...

Sorting an array of arrays by the child array's length?

What's the best way in PHP to sort an array of arrays based on array length? e.g. $parent[0] = array(0, 0, 0); $parent[2] = array("foo", "bar", "b", "a", "z"); $parent[1] = array(4, 2); $sorted = sort_by_length($parent) $sorted[0] = array(4, 2); $sorted[1] = array(0, 0, 0); $sorted[2] = array("foo", "bar", "b", "a", "z"); ...

Why are multi-dimensional arrays in .NET slower than normal arrays?

Edit: I apologize everybody. I used the term "jagged array" when I actually meant to say "multi-dimensional array" (as can be seen in my example below). I apologize for using the incorrect name. I actually found jagged arrays to be faster than multi-dimensional ones! I have added my measurements for jagged arrays. I was trying to use a ...

deleting rows of a numpy array based on uniqueness of a value

let's say I have a bi-dimensional array like that numpy.array([[0,1,1.2,3],[1,5,3.2,4],[3,4,2.8,4], [2,6,2.3,5]]) I want to have an array formed eliminating whole rows based on uniqueness of values of last column, selecting the row to keep based on value of third column. e.g. in this case i would like to keep only one of the rows with ...

Java generics and array initialization

What's the explanation for the following: public class GenericsTest { //statement 1 public ArrayList<Integer>[] lists; public GenericsTest() { //statement 2 lists = new ArrayList<Integer>[4]; } } The compiler accepts statement 1. Statement 2 is flagged by the compiler for "generic array creation"....

What is the O time in determining if a value is in a sorted array?

I have a sorted array of 5000 integers. How fast can I tell if a random integer is a member of the array? An answer in general, C and Ruby would be nice. The array values are of the form c*c+1 where c can be any integer from 1 to 5000 i.e. [2, 5, 10, 17, 26, 37, 50 ...] ...

Allocating unmanaged memory in managed .NET code

Hi I have a unmanaged function that takes a chunk of memory allocated by malloc and deallocates it later on in async manner. I want to wrap it into managed wrapper. Is following code OK? void managed_fx (byte data __gc[], size_t size) { // Pin the data byte __pin *pinned_data = &data [0]; // Copy data to the unmanaged buf...

How to pass an array size as a template with template type?

My compiler behaves oddly when I try to pass a fixed-size array to a template function. The code looks as follows: #include <algorithm> #include <iostream> #include <iterator> template <typename TSize, TSize N> void f(TSize (& array)[N]) { std::copy(array, array + N, std::ostream_iterator<TSize>(std::cout, " ")); std::cout << s...

Validate each element in an array?

Hello, I am currently trying to validate a form server side, the way it works is all the data is put into and array, with the form field as the key and and the field data as the value, however I need to check that all the keys have a value associated with other wise I want the submittion to stop and the user having to edit there detail...

Java int[][] array - iterating and finding value

Hi I have an array in the form of 'int[][]' that represents the co-ordinates of a small grid. Each co-ordinate has been assigned its own value. eg array[0][4] = 28...... I have two questions. Firstly, how do I iterate through all the stored values. Secondly, I want to be able to input a value and have its specific co-ordinates in the g...

Is Object constructor called when creating an array in Java?

In Java, an array IS AN Object. My question is... is an Object constructor called when new arrays is being created? We would like to use this fact to instrument Object constructor with some extra bytecode which checks length of array being constructed. Would that work? ...

Create an array of integers property in Objective C

I'm having troubles creating a property of an array of integers in Objective C. I'm not sure whether this is even possible to do in Obj-C so I'm hoping someone can help me in finding out either how to do it correctly or provide an alternative solution. myclass.h @interface myClass : NSObject { @private int doubleDigits[10]; } @proper...

Array functions in jQuery

Hi, I am using jQuery in my web-app I want to use arrays, but I am not able to find out functions for arrays (add, remove or append elements in array) in jquery, Can anyone share with me any link related to jQuery array functions which will explain the jquery array functions. Thanks ...

PHP/MySQL - building a nav menu hierarchy

So the final menu will look something like this: Item B Item B-1 Item B-1-2 Item B-1-1 Item A SubItem A-1 SubItem A-2 Item C Based on the following DB records: id menu_title parent_menu_id menu_level weight 1 Item A 0 1 ...