arrays

C homework help: Searching through arrays

I'm working on a problem where I'm given a sorted array of integers, and I am supposed to take an input from the user, search for the input, and return the first instance of that input (if it exists) and the number of times it appears. I wrote a program with the following approach: I take an input from the user. I then use binary search...

Why is my return value not allowing me to compile? (See pastie'd code inside)

Hey there. I am trying to return an array, but the compiler is telling me that it's an incompatible type..? My code: http://pastie.org/private/v4xn4eahkojftsghudf1g I'm a beginner at Java, sorry about this :) Thanks very much. ...

How to get the size of each value of a hash

hi! I have a hash, each value is an array. I want to build a new array containing the size of each value/array. Example: the hash {"A"=>["1", "2", "3"], "B"=>["b", "toto"]} the result [3, 2] thanks for your help ...

Why am I getting array elements with "0"? (See pastie inside)

Hey there. Java beginner here :) Well, I'm having a few troubles with this program: http://pastie.org/private/sfqqnqwxtpgtuhswpqepw 1) I want my program to split up the "input" array into an oddList, evenList and negativeList set of arrays. However, when splitting it up, it is adding a bunch of elements as "0". 2) 0 needs to be added o...

Problem getting value from multi-dim-array

The following code: $options = $value[$i]['options']; print_r($options); outputs the following result: Array ( [0] => stdClass Object ( [id] => 1 [field_id] => 1 [option_name] => I'm a normal user ) [1] => stdClass Object ( [id] => 2 [field_id] => 1 [option_name]...

Unpacking 3-byte/24-bit data chunks with Ruby

I am building a pure-Ruby WAV file read/write library, learning deeper Ruby functionality as I go. It currently works well with 16-bit audio, as I am able to use String.unpack('s*') to pull individual audio samples out into an array of signed integers. I am having trouble wrapping my mind around how to go about dealing with 24-bit audio,...

multilevel menu with multilevel array

Dear all, just want to ask anyone here can solve this problem? I want to create a multilevel menu by generate with multilevel array. I just can't get perfect solution, it always got array_push error. My study the original idea come from http://www.weberdev.com/get_example-4830.html But still cannot match my need. This is My MySQL [...

Would These Be Considered Magic Numbers?

Hi, I've just completed writing a program for a programming class, and I want to avoid use of magic numbers, so here's my question: In the function below, would my array indexers be considered magic numbers? Code: string CalcGrade(int s1, int s2, int s3, double median) { const int SIZE = 23; const int LETTER_GRADE_BARRIERS[SIZE] = { ...

Optimal way of finding whether any element is repeated in a given array?

What is the best optimal way of finding whether any element is repeated in a given array? ...

Retreive value from an Array in Cakephp

Hi Guys, I am trying to get some data to display from an Array in Cakephp, the Array has all the data from a find() output and other parts of the data output fine. The data i am trying to access is the name field inside company , the code i am using is echo $quote['Company']['name'] but it returns and error saying that the index is un...

Actionscript 3 setting multiple variables of an object in an array possible?

Right now, I have many MovieClips's in my array. I want to update all the alpha values of the MovieClips in my array. Right now, I am using a for loop but this is not the fastest way to do it. Is there a way to set values for all the items in my array? Thanks! ...

PHP: How do I check the contents of an array for my string?

Hi, I a string that is coming from my database table say $needle. If te needle is not in my array, then I want to add it to my array. If it IS in my array then so long as it is in only twice, then I still want to add it to my array (so three times will be the maximum) In order to check to see is if $needle is in my $haystack array, do...

Create a CSV file with PHP

I need to create a CSV file from a PHP array, I'm aware of the fputcsv() function. I've a recollection that a better function exists for this kind of stuff but I can't find it nor remember it's name. Does anyone know of such function or am I imagining? I might be making some confusion with the fgetcsv() function and the str_getcsv() ...

How to cast array elements to strings in PHP?

If I have a array with objects: $a = array($objA, $objB); (each object has a __toString()-method) How can I cast all array elements to string so that array $a contains no more objects but their string representation? Is there a one-liner or do I have to manually loop through the array? ...

Get part of an array

Hello ! I have an array: $array = array( 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', ); and I would like to get a part of it with specified keys - for example key2, key4, key5. Expected result: $result = array( 'key2' => 'value2', 'key4' => 'value4', 'key5' => ...

Find minimal and maximun date in array using LINQ?

I have an array of classes with a property Date, i.e.: class Record { public DateTime Date { get; private set; } } void Summarize(Record[] arr) { foreach (var r in arr) { // do stuff } } I have to find the earliest (minimum) and the latest (maximum) dates in this array. How can I do that using LINQ? ...

How do I get a random result from a preg_match_all ?

(Sorry if the title is pretty useless) I have this function to get the first image from a random post in WordPress. This works great, but now I need it to select a random image from all the matches, rather than the first. (I'm running this function in a query_posts loop to select the categories) // Get first image in post function catc...

Flash browser app ActionScript: how to extract a subset of objects from a sorted array *efficiently*?

I have a browser-deployed Flash app (not an AIR app with access to SQLConnection) and it fetches JSON results from a remote server via HTTPService. I need to extract subsets from the returned resultset, an array of objects, efficiently. Mutltiple calls through the cloud to the back-end won't do. It all has to happen client-side. Is t...

What's the best way of creating a readonly array in C#?

I've got the extremely unlikely and original situation of wanting to return a readonly array from my property. So far I'm only aware of one way of doing it - through the System.Collections.ObjectModel.ReadOnlyCollection<T>. But that seems somehow awkward to me, not to mention that this class loses the ability to access array elements by ...

Two-dimensional variable-length array in Cobol

How do you go about defining a two-dimensional MxN array in Cobol of which both M and N are of variable length? Here's the message I get in Net Express when attempting to have a variable array inside another: COBCH0144S OCCURS DEPENDING subsidiary to OCCURS only allowed with ODOSLIDE ...