arrays

How much should I add when resizing an array?

I'm having a contest with another student to make the fastest version of our homework assignment, and I'm not using an ArrayList for performance reasons (resizing the array myself cut the benchmark time from 56 seconds to 4), but I'm wondering how much I should resize the array every time I need to. Specifically the relevant parts of my ...

How can I get a new array from the second item onwards in c#?

I originally had this code which I mistakenly thought would do what I wanted it to: string firstArg = args[0]; string[] otherArgs = args.Except(new string[] { args[0] }).ToArray(); However, it seems that the .Except method removes duplicates. So if I was to pass through the arguments a b c c, the result of otherArgs would be b c not ...

What method is needed to have the "-" ( subtract ) method working with Ruby arrays?

If I have two arrays a and b, what method should the object contained have to override so the subtract method - works properly? Is it enough with eql? EDIT I'm adding more detail to my question. I have this class defined: class Instance attr_reader :id, :desc def initialize( id , desc ) @id = id.strip @d...

how to create array string

hi all, i'm having NSMutableArray which containing student info, now i just want to extract student name and their average mark only, so what i did NSMutableArray *stuCollection = [[NSMutableArray alloc] initWithCapacity:[students count]]; for (int i = 0; i < [students count]; i++) { if([students objectAtIndex:i] != NULL) { N...

Finding a path in a multidimensional array for a certain ID

I have an array that's stored like this: [0] => Array ( [id] => 1 [cat_name] => c1 ) [1] => Array ( [id] => 2 [cat_name] => c2 [copii] => Array ( [0] => Array ( [id] => 5 [cat_name] => c21 ...

When in optimization phase, would it be smart to pass all array by ref?

In PHP, When we get to the optimization phase of the application (I am speaking about an app that handles hundreds of thousands of users) would it be smart to pass all arrays (where I do not mind what happens to them after I pass them to the function) by ref? ...

Need help with declarations in C

How do I do the following declaration? int main(int argc, char *argv[]) { char *users[] = {}; char *names[] = {}; openPasswd(users, names); return 0; } void openPasswd(char &users[] = {}, char &names[] = {}){ } I want to populate the 2 char arrays from the function back to the main program. How do I do this? ...

What line(s) this code might throw a "Index was outside the bounds of the array" exception?

A little background on this error: The customer getting this error message in their log file and support hasn't been able to reproduce it yet. So I'm reviewing the code trying to determine what may be happening. I have narrowed it down to this section of the code by reviewing their log file. I didn't write this code, but it's purpose...

How to use a c-type array as an ivar?

I need a good old-fashioned 2-dimensional array of integers in my program, but no matter how I try to declare it as an ivar, and then use @property/@synthesize, I get one compiler complaint or another. I declare int spotLocations[10] [10] as an ivar. That much works, but then the @property/@synthesize process never passes must...

Java: Setting array length for an unknown number of entries

I am trying to fill a RealVector (from Apache Commons Math) with values. I tried using the class's append method, but that didn't actually add anything. So now I'm using a double[], which works fine, except I don't know in advance how big the array needs to be. private void runAnalysis() throws IllegalArgumentException, IllegalAccessExc...

Character arrays question C++

Is there any difference between the below two snippets? One is a char array, whereas the other is a character array pointer, but they do behave the same, don't they? Example 1: char * transport_layer_header; // Memory allocation for char * - allocate memory for a 2 character string char * transport_layer_header = (char *)malloc(2 * si...

I need help parsing a PHP array for an embedded Google Calendar

I'm not sure I'm headed on the right path but what I want to do is have an embedded Google Calendar with multiple calendars encoded in the iframe source. Example: <iframe src="https://www.google.com/calendar/embed?src=cjvssf4vj98hoa4os5hr26fmcg%40group.calendar.google.com&amp;amp;src=cjvssf4vj98hoa4os5hr26fmcg%40group.calendar.google.co...

Most elegant way to get the array element by position?

I have an array: private int[,] _blocks = new int[6, 4]; It represents a set of blocks which is 6 deep horizontally and 4 deep vertically. Graphically it looks like this: I need a function that would take in a number, from 1 to 24 and return the array element that matches. So for number 14, I'd get back _blocks[1, 2]; I've creat...

How to add to end of array C#?

How do I add a new item from a TextBox and Button on a Windows Form at the end of an ArrayList which references a class? private product[] value = new product[4]; value[1] = new product("One",5) value[2] = new product("Two",3) value[3] = new product("Three",8) Workflow Enter new products details into textbox1, textbox2, textbox3 W...

What is the best way to search for an item in a sorted list in javascript?

I have an ordered list of integers, and would like to search through them. What is the fastest way to do this? Is this the fastest it will work? Or can we optimise it because it is ordered? Array.prototype.Contains = function(value) { for (var index = 0; index < this.length; index++) { if (value == this[index]) { ...

javabat question

Return an array that contains the exact same numbers as the given array, but rearranged so that all the zeros are grouped at the start of the array. The order of the non-zero numbers does not matter. So {1, 0, 0, 1} becomes {0 ,0, 1, 1}. You may modify and return the given array or make a new array. zeroFront({1, 0, 0, 1}) → {0, 0, 1, ...

Pushing data into array with JavaScript.

Hi, I'm relatively new to JavaScript and I've been having trouble pushing data into an array. I have two dynamic vars and I need the array to be formatted like: var array = [[-373597200000, 315.71], [-370918800000, 317.45], [-368326800000, 317.50]]; I already have a loop running for each iteration of the vars, I'm just not sure how I...

Write a function int caluculate_sum(int *a, int size) that calculates the sum of all the elements in an array.

This is what I was given to start with. int main(){ int a[5] = {0,1,2,3,4}; printf("Sum of elements of a: %d\n", calculate_sum(a,5)); return 0; } Here's what I've got, I don't know why it doesn't work, please help me. #include <stdio.h> int main() { int a[5] = {0,1,2,3,4}; int b; ...

What's C++ Really Doing When I Accidently Use a Variables to Declare Array Length?

I was helping a friend with some C++ homework. I warned said friend that the kind of programming I do (PHP, Perl, Python) is pretty different from C++, and there were no guarantees I wouldn't tell horrible lies. I was able to answer his questions, but not without stumbling over my own dynamic background. While I was reacquainting myse...

PHP Associative Array Strucuture

Is there any thing wrong with this array? $selects = array( "getmoney1" => $money["Dimes"], "getmoney2" => $money["Nickels"], "getmoney3" => $money["Quarters"] ); I am learning, and I want to know more, and how to do it right. ...