arrays

recursive array_diff()?

I'm looking for some tool to give me a recursive diff of two arrays. What I envision is a web page with two color-coded tree-structures. On each tree, green are parts of the array which match in both arrays, and red is for parts of each that don't match the other. Something like the output of dBug I have some code that gives me a nested...

How to create an Array or ArrayList of objects in C#?

I have custom object MyClass and I need to create 3 instances of it. Instead of doing something dumb like: MyClass instance1 = new MyClass(); MyClass instance2 = new MyClass(); MyClass instance3 = new MyClass(); Shouldnt I be able to do something like this: MyClass[] instances = new MyClass(); instances[0].somemethod; ? ...

in C++ how can I pass a static array to an object as a parameter, and modify the original array in there?

The array has to be on the stack, and I need to modify the elements. Here is what I have: Class Me { private: int *_array; void run(){ for (int i = 0 ; i < 10; ++i) { _array[i] += 100; } } public: Me(int array[]) { _array = array; } }; This is main: int array[10] = {0, 1...

deleting rows in numpy array

I have an array that might look like this: ANOVAInputMatrixValuesArray = [[ 0.96488889, 0.73641667, 0.67521429, 0.592875, 0.53172222], [ 0.78008333, 0.5938125, 0.481, 0.39883333, 0.]] Notice that one of the rows has a zero value at the end. I want to delete any row that contains a zero, while keeping any row that contains non-zero v...

how to bubble sort through a text file in java

How do I properly bubble sort through a text file by assigning the values to an array. In the code below I tried to assign the values from the text file to a string while there is still something to fetch. Then I used a for loop to assign the one that I have fetch to the array. Then tried to use the bubble sort to hopefully sort the numb...

How to check that an array contains a particular value in Scala 2.8?

I've got an array A of D unique (int, int) tuples. I need to know if the array contains (X, Y) value. Am I to implement a search algorithm myself or there is a standard function for this in Scala 2.8? I've looked at documentation but couldn't find anything of such there. ...

Finding the longest down sequence in a Java array

Given this array int [] myArray = {5,-11,2,3,14,5,-14,2}; I must be able to return 3 because the longest down sequence is 14,5,-14. What's the fastest way to do this? PS: Down sequence is a series of non-increasing numbers. ...

Java Reflection API - Getting the value of a String[] field.

I was wondering if it is possible to grab a String[] of an unknown size from a class using the java reflection API and store it elsewhere? Thanks. ...

Initializing 2D Array In Class Constructor in C++

I define a 2D array in my header file char map[3][3]; How can I initialize the values in the class constructor like this map = {{'x', 'x', 'o'}, {'o', 'o', 'x'}, {'x', 'o', 'x'}}; ...

string array in c

How do you use a string array as a parameter in C? If I were to write a function with signature: Guess i didnt explain myself very well... I'll post the code that i'm trying to get to work. int format_parameters(char* str) { char local_str[201] = ""; int i = 0; int j = 0; int flip = 0; while(str[i]) { if(...

How to convert the a java type to java string []?

I want to ask a Java String[] question. In the java, if a variable convents to another, it can add the (String), (int), (double),... before the variable in the left hand side. However, is there something like (String[]) in Java as I want to convent the variable into (String[]). ...

Arithmetic Progression in Python without storing all the values

Hello, I'm trying to represent an array of evenly spaced floats, an arithmetic progression, starting at a0 and with elements a0, a0 + a1, a0 + 2a1, a0 + 3a1, ... This is what numpy's arange() method does, but it seems to allocate memory for the whole array object and I'd like to do it using an iterator class which just stores a0, a1 and ...

Numpy - add row to array

Hi, How does one add rows to a numpy array? I have an array A: A = array([[0, 1, 2], [0, 2, 0]]) I wish to add rows to this array from another array X if the first element of each row in X meets a specific condition. Numpy arrays do not have a method 'append' like that of lists, or so it seems. If A and X were lists I would merely...

In C# and also Java, what's the relationship between Object[] and String[]?

I recently started to think of this problem and I can't find the answer. The following code compiles and executes as expected object[] test = new string[12]; However, I don't know why. I mean, should we consider string[] as the derived class of object[]? I think in C#, every array is an instance of Array class. If Array is generic, i...

I need to create 2D array in C#

Hi I need to create 2D jagged array. Think of a matrix. The number of rows is known, the number of columns is not known. For example I need to create array of 10 elements, where type of each element string[]. Why do I need that? The number of columns is not known - this function must simply do the allocation and pass array to some other...

When to use ArrayList over array in recursion

So I have this problem. I was trying to code a program to print all the valid possible arrangements of brackets i.e. for 3 brackets we can have ((())), (()()), ()()(), (())() etc. I have a working code public static void main(String[] args) { int number = 3; // No. of brackets int cn = number; int on = number; // open ...

PHP Array_Unique Problem

I don't know PHP very well, so please bear with me. My client has a database with information and one of the fields is ff_date_time in the format "Tue Oct 5 14:43:10 2010". There are a lot of entries in here and I need to display a list of just the days that have entries: ie, Tue Oct 5, 2010Thurs Oct 7, 2010 and so on. There may be hu...

Initialize runtime value-type array with specific value?

Hello, Is there a way I can initialize the following runtime array to all trues without looping over it using a foreach? Here is the declaration: bool[] foo = new bool[someVariable.Count]; Thanks! ...

Three greatest values in an array

To find the three greatest elements in an array(length 100), is a combination of a for loop and an if statement(s) the most effective way, or is there a more efficient method? ...

Convert javascript array handling to jQuery

Hi everyone I'm doing a javascript assignment and have just learned that I can do it in jQuery if I wish, rather than vanilla javascript. I thought I'd give it a go to see what it's like. This is the contents of my javascript function: rowsArray = $("#Table1 tr"); for (i=0;i<rowsArray.length;i++){ numSeatsInRow = rowsArray[i]...