arrays

Interview Question: How to efficiently search in an ordered matrix?

I have a x by y matrix, where each row and each column are in ascending order as given below. 1 5 7 9 4 6 10 15 8 11 12 19 14 16 18 21 How to search this matrix for a number in O(x+y)? I was asked this question for an interview, but could not figure out the way. Curious to know if it could be done. ...

PHP question about multidimensional array

My array looks like this: Array ( [Bob] => Red [Joe] => Blue ) But it could be any number of people, like this: Array ( [Bob] => Red [Joe] => Blue [Sam] => Orange [Carla] => Yellow) Basically I want PHP to take this array and echo it so that it comes out looking like: Bob - Red Joe - Blue Sam - Orange Carla - Yellow I know I nee...

[myLabel setText:] only works if I use an intermediate variable

I am trying to set the text of a UILabel to be equal to the name of the day of the week represented in an NSDateComponents. I am using the following code: NSDateComponents *dateComponents = [[[NSDateComponents alloc] init] autorelease]; dateComponents.weekday = 1; //Sunday NSString * const weekdayNames[8] = {@"Array starts at 1", @"Sun...

Replace a substring in each element of a string array?

Hey, I have an array of strings and I want to replace a certain substring in each of those elements. Is there an easy way to do that besides iterating the array explicitly? Thanks :-) ...

PHP: creating an XML string for fusioncharts help

hi, I'm using fusioncharts with PHP but I'm getting a No data to display error. I'm adding data to the chart via xml generated from an array. the data exists as when I dump the array I can see it all fine. I think it's the xml that is wrong. Maybe someone can have a look and help me out, the xml var dump is being wierd. Creating the ar...

Get id's and add to array, delete from array jquery

Hello, i have the current .each in my javascript var divs = array(); $('.div-item').each(function(){ var id = $(this).attr('id'); divs.push(id); }); How would I delete an id from the array programmatically? ...

unsetting an array within an array

In the screenshot, you can see i have an array of arrays. I need to find an array that contains say, 'Russia', and unset it completely. That is, for Russia, remove the element [303]. I've played around with array search but I'm sure theres a funkier way of doing this. Chris. ...

How can I loop through a Perl array of arrays of hashes?

I would like to print an Array of Arrays of Hashes, so I looked at perldsc, and ended up with for my $j (0 .. $#aoaoh) { for my $aref (@aoaoh) { print '"' . join('","', @$aref[$j]), "\"\n"; } } but it doesn't work. Does anyone know how to do this? ...

FusionCharts: Using PHP class chart doesn't show, just see 'Chart' text.

Hi I'm using fusioncharts with PHP. I'm generating the chart from an array like i've shown. I don't get any errors but all I get is no chart but the word "Chart" displayed. include ('classes/FusionCharts_Gen.php'); $ticketobj = new SupportTickets(); $types = $ticketobj->getIssueTypes(); $FC = new FusionCharts("Column3...

Javascript Arrays - Consolidating Multiple Arrays Help

Hi Guys, I wonder if anybody could provide me with any assistance to the following problem I am having with my JS project? I basically have information about a product being pulled from out from 3 different JSP lists: A Product's Details A Products's Ratings A Products's Retailers What I am trying to a do is loop through the JSP th...

specify dtype of each object in a python numpy array

This is a similar question using dtypes in a list The following snippet creates a "typical test array", the purpose of this array is to test an assortment of things in my program. Is there a way or is it even possible to change the type of elements in an array? import numpy as np import random from random import uniform, randrange, c...

javascript: missing : after property id

I'm trying to pass my own array of objects: results[num_row] = {'title:\'' + title + '\', ' + 'url:\'' + url + '\''}; but this returns the error in firebug when I try: results[num_row] = {title:'Link A', url:'/page1'} it works. Thanks, <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xh...

How do I delete a member of $_REQUEST?

$_REQUEST['delete_me']; Array ( [action] => test [city_name] => Orlando [delete_me] => - ); Can I just delete it or will setting it to $_REQUEST['delete_me'] = ""; do the trick? ...

Best way to convert an array of integers to a string in Java

In Java, I have an array of integers. Is there a quick way to convert them to a string? I.E. int[] x = new int[] {3,4,5} x toString() should yield "345" ...

Evaluate a dynamic array key

I have a form that allows the user to add information an their leisure. They can add locations via jQuery in my form so when recieving the data I may have 1 location or 10. Each location has attributes like phone, address, etc. In my form the input names are appended with _1 , _2, etc to show its a new set of data. That is working swimmi...

Sorting an Array

Hello, I have an array containing all string values. Contents of the array are order_id, waypoint_x, waypoint_y. How do I sort it based on order_id and have the results like 1, 2, 3, 4.... (i.e. as if the field was an integer type and string) When I use the waypoints as the array is at the moment the results come out 1, 10, 11, 12... ...

CommunicationObjectAbortedException during reading large array from server

Hello, I'm receiving such exception during reading array of 40000 items. Is there an idea why does it happen. I've changed send/receive timeout to 30 min. Not helped. System.ServiceModel.CommunicationObjectAbortedException was unhandled by user code Message=The socket connection has been disposed. Source=mscorlib StackTrace: ...

How can I concatenate ranges of numbers into an array in MATLAB?

For example, I want to combine two ranges of numbers like this: 1 2 3 4 5 11 12 13 14 15 16 17 18 19 20 So, I tried: a = 1:5,11:20 but that didn't work. I also want to do this in a non-hardcoded way so that the missing 5 elements can start at any index. ...

Sorting an Array of strings with capital and lowercase letters in C

Is there a way to sort an array of strings in alphabetical order where the strings contain both capital and lowercase letters? Because capital letters have a lower ASCII value so functions like strcmp would always show that it is before a lower case letter. For example, lets say we wanted to sort "ABCD", "ZZZZ", "turtle", "JAVA", "wate...

Assigning a const char[] do you need to put in a null term

We are setting a char [] to some hex values i.e. char [] test1 = {0x30,0x31,0x32,0x33,0x34,0x35}; Then we copy it into a string using string teststring(test1, sizeof(test1)); Is the array suppose to be null terminated? or is the way we do the assignment, C++ is smart enough to know that its null terminated and have it appended anyh...