arrays

How do I best handle dynamic multi-dimensional arrays in C/C++?

What is the accepted/most commonly used way to manipulate dynamic (with all dimensions not known until runtime) multi-dimensional arrays in C and/or C++. I'm trying to find the cleanest way to accomplish what this Java code does: public static void main(String[] args){ Scanner sc=new Scanner(System.in); int rows=sc.nextInt(); int co...

How are javascript arrays implemented?

Namely, how does the following code: var sup = new Array(5); sup[0] = 'z3ero'; sup[1] = 'o3ne'; sup[4] = 'f3our'; document.write(sup.length + "<br />"); output '5' for the length, when all you've done is set various elements? EDIT: Forget the comparison to using it like a hashmap. I think this was confusing the issue. My 'problem' ...

Implement Array-like behavior in JavaScript without using Array

Is there any way to create an array-like object in JavaScript, without using the built-in array? I'm specifically concerned with behavior like this: var sup = new Array(5); //sup.length here is 0 sup[0] = 'z3ero'; //sup.length here is 1 sup[1] = 'o3ne'; //sup.length here is 2 sup[4] = 'f3our'; //sup.length here is 5 The partic...

Search Javascript Array for Regex and return True/False (0/1) if found

I need to know how I can search an array for some literal text and have it used as a condition whether to continue. Heres why: Each time I execute a function I am pushing the ID of the property it acts upon into an array. I need my funtion to check if that ID is in the array already and if it is, remove it and execute my other function ...

multi words PHP arrays replacement

<?php $string = 'The quick brown fox jumped over the lazy dog.'; $patterns[0] = '/quick/'; $patterns[1] = '/brown/'; $patterns[2] = '/fox/'; $replacements[0] = 'slow'; $replacements[1] = 'black'; $replacements[2] = 'bear'; echo preg_replace($patterns, $replacements, $string); ?> Ok guys, Now I have the above code. It just works well. N...

Using elements of a constant array as cases in a switch statement

I'm attempting to map a set of key presses to a set of commands. Because I process the commands from several places, I'd like to set up a layer of abstraction between the keys and the commands so that if I change the underlying key mappings, I don't have to change very much code. My current attempt looks like this: // input.h enum LOG...

VB.NET Predicate Array Find

How would I convert the following to a VB.NET predicate using Array.Find? Private Function FindCulture(ByVal Code As String) As Globalization.CultureInfo ' Dim AllCultures As Globalization.CultureInfo() = Globalization.CultureInfo.GetCultures(Globalization.CultureTypes.AllCultures) ' For Each Culture As Globalization.Cul...

Finding difference less than the average in an unsorted array?

Hi, I need to find 2 elements in an unsorted array such that the difference between them is less than or equal to (Maximum - Minimum)/(number of elements in the array). In O(n). I know the max and min values. Can anyone think of something? Thank you! ...

How to delete an element from an array in php?

Hi, does anyone know an easy way to delete an element from a php array? I mean so that foreach($array) no longer includes that element. I thought that setting it to null would do it, but apparently not. Thanks, Ben ...

How to skip the 1st key in an array loop?

I have the following code: if ($_POST['submit'] == "Next") { foreach($_POST['info'] as $key => $value) { echo $value; } } How do I get the foreach function to start from the 2nd key in the array? Thanx. ...

Java nested list to array conversion

What is the most efficient way to convert data from nested lists to an object array (which can be used i.e. as data for JTable)? List<List> table = new ArrayList<List>(); for (DATAROW rowData : entries) { List<String> row = new ArrayList<String>(); for (String col : rowData.getDataColumn()) row.add(col); table.add...

Java: Generics, arrays, and the ClassCastException

I think there must be something subtle going on here that I don't know about. Consider the following: public class Foo<T> { private T[] a = (T[]) new Object[5]; public Foo() { // Add some elements to a } public T[] getA() { return a; } } Suppose that your main method contains the following: Foo<Double> f = new Foo...

Why is "array" a reserved word in C/C++?

Visual Studio syntax highlighting colors this word blue as if it were a keyword or reserved word. I tried searching online for it but the word "array" throws the search off, I get mostly pages explaining what an array is. What is it used for? ...

How can I write out or read in a Perl hash of arrays?

I have a program in Perl I'm working on where I would need multiple keys, and a way of giving each key multiple values and follow that by being able to both read them in and write them out to an external file depending on if the key matches what the person enters into standard input. I've looked across several sites and have found inform...

Is there a Java array/list which is statically typed AND variable length

This would be very handy as typecasting gets boring fast. ...

Helper functions for marshalling arrays of structures (with pointers)

This appears to be the most commonly asked C# interop question and yet seems to be difficult to find a working solution for. I am in need of allocating an array of matrix datastructure in C# passing it to a C DLL which fills up the data and returns it to the caller to deal with. Based on various pages on the web, I seem to have managed...

C++ char array with stdin

I am trying to get the size of an array populated by stdin: char *myArray; cin >> myArray cout << sizeof(myArray); This returns 4 when I enter a string greater with a length greater than 4 e.g. "40905898" Where am i going wrong? ...

C++ How can I iterate till the end of a dynamic array?

suppose I declare a dynamic array like int *dynArray = new int [1]; which is initialized with an unknown amount of int values at some point. How would I iterate till the end of my array of unknown size? Also, if it read a blank space would its corresponding position in the array end up junked? Copying Input From users post below: ...

(C++) While reading a file (ifstream), is there any way to direct it to make a new line?

While reading a file (ifstream), is there any way to direct it to make a new line? For instance, I would like for THIS to happen: myfile>>array[1]>>array[2]>>endl; Obviously, the "endl" just isn't allowed. Is there another way to do this? Edit---thanks for the quick responses guys! From a text file, I'm trying to store two strings...

Copy string to pointer to pointer

I am using this example: char *myData[][2] = {{"John", "[email protected]"}, {"Erik", "[email protected]"}, {"Peter","[email protected]"}, {"Rikard","[email protected]"}, {"Anders","[email protected]"}}; char **tableData[6]; tableData[0] = myData[0]; tableData[1] = myData[1]; tableData[2] = myData[2]; tableData[3] = myData[3]; tableData[4] = ...