arrays

how to get the most frequent items

Hi guys. I am working on an application which has a large array containing lines of numbers, transNum[20000][200]//this is the 2d array containing the numbers and always keep track of the line numbers I am using a nested loop to look for the most frequent items. which is for(int i=0/*,lineitems=0*/;i<lineCounter;i++) { for(in...

Deleting duplicates in the array

I made a program to delete duplicates in an array but the program's if condition always remain true. I understood what the problem was,changed arr[i] to arr[count] and allocated memory via malloc,but the program prints the array as it is without deleting the duplicates. # include<stdio.h> # include<stdlib.h> int count=0; ...

Algorithm for sorting and pairing elements of 2 arrays

Hi, I am trying to configure an efficient algorithm (faster than O(n^2)) for sorting and pairing elements between 2 arrays. However this needs to work under the premise that neither array's elements can be compared to other elements in their own array. Edit: The elements of the arrays are "sizes" which correspond to particular objects. ...

compare an array of enums in (Objective) C

I want to test for transition from one state to another. I have defined my states in an enum like this: enum FingerStatus { FINGERS_UP, MOVING, FINGERS_STILL }; I have a "currentState" and a "newState" variable. I know that enums are just integers, and if they're 16-bit integers, which I think they are, it's possible to represent two ...

PHP, SimpleXML arrays. Unanticipated casting of an array to a string

Sample XML: <root> <ratings>3</ratings> <ratings>5</ratings> <ratings>7</ratings> </root> The following code is the basis for my small application, it works as would be expected: <?php // $xml is some simplexml object sizeof($xml->ratings); //3 foreach($xml->ratings as $rating){ echo($rating->value."::"); //thi...

How do I pick a selection of rows with the minimum date difference.

Hi, The question was difficult to phrase. Hopefully this will make sense. I have a table of items in my INVENTORY. Let's call the items Apple, Orange, Pear, Potato. I want to pick a basket of FRUIT (1 x Apple,1 x Orange, 1 x Pear). Each item in the INVENTORY has a different date for availability. So that... Apple JANUARY Apple FEB...

Error adding object to mutable array

for (NSString *CurrentArtistName in ArtistNamesArray) { CurrentArtistName = [CurrentArtistName stringByMatching:regEx capture:1]; NSLog(CurrentArtistName); [ArtistNames addObject: CurrentArtistName]; } why is this closing my app ? There are no errors in the coding and the NSLog is logging the CurrentArtistName ? i really ...

Help with For Loop. Values repeating

$teams = array(1, 2, 3, 4, 5, 6, 7, 8); $game1 = array(2, 4, 6, 8); $game2 = array(); if teams[x] is not in game1 then insert into game2 for($i = 0; $i < count($teams); $i++){ for($j = 0; $j < count($game1); $j++){ if($teams[$i] == $game1[$j]){ break; } else { array_push($game2, $teams[$i]);...

How to iterate backwards in an array in C?

I am trying to input a string of characters, and then output them backwards like Input: Hello Output: olleH I have a working example, however I am getting every single letter except the last. #include <stdio.h> #include <stdlib.h> #define MAX_SIZE 100 int main(void) { int my_stg2[MAX_SIZE]; int i = 0; int j; char my_stg[MAX_SIZE]; ...

Define array, then change its size....

I come from a java background and there's something I could do in Java that I need to do in C++, but I'm not sure how to do it. I need to declare an array, but at the moment I don't know the size. Once I know the size, then I set the size of the array. I java I would just do something like: int [] array; then array = new int[someSi...

Javascript arguments as array?

so I have a button with this event: onmousedown="hideElements('\x22cartview\x22,\x22other\x22')" and then this function hideElements: function hideElements(what) { var whichElements=[what]; alert(whichElements[0]); } I want it to alert "cartview" but it alerts "cartview","other" I am aware of the arguments object ...

how can i create array with foreach in php?

hi guys, i am trying to create array like in the example i wrote above: $arr=array('roi sabah'=>500,yossi levi=>300,dana=>700); but i want to create it dynamic with foreach. how can i do it ? thanks. ...

php :: remove options from array that already exist?

Hi guys, I have two arrays one like 1 | 1st name 2 | 2nd name 3 | 3rd name 4 | 4th name and one like 1st name 2nd name 3rd name 4th name 5th name 6th name 7th name Basically I want to intersect these arrays I need to interesect these arrays so I end up with the second array being just 5th name 6th name 7th name How would...

php :: shorten this function? :: array manipulation

Hi guys, So I have a function as detailed below, I believe it is too long and can be shortened. I think I have fallen over in the array manipulation part. Please ignore the strange database syntax So basically this function is given a string like this abc, def, ghi, jkl, mno due to some glitches it can be received with an extra...

PHP - How do I add a key => value to a specific part of an multidimensional array?

How would I insert a key => value pair into the midst of a nested array? example: array 1 => string 'a' (length=1) 2 => string 'b' (length=1) 3 => array 'this' => string 'that' (length=4) 'meh' => string 'foo' (length=3) 'blah' => array 'a' => int 1 'b' => int 2 4 => arra...

Returning booleans in a C# method

I have an array of booleans which gets filled by a loop. The method that owns the array needs to return a single boolean. So can I do this: bool[] Booleans = new bool[4]; // do work - fill array return (Booleans[0] && Booleans[1] && Booleans[2] && Booleans[3]); So if I have: T,T,F,T will I get F back since there is one in the array ...

php ::Array references...

Hi guys, any idea why foreach ($groups as &$group) $group = trim(str_replace(',', '', $group)); echo '<pre>'; print_r($groups); echo '</pre>'; $groupsq = $groups; foreach ($groupsq as &$group) $group = '\'' . $group . '\''; echo '<pre>'; print_r($groups); echo '</pre>'; Yields Array ( [0] => Fake group [1] => another ...

Java Array Resizing

Ok so I'm supposed to resize an image given to me by half using arrays. I have no idea where to begin. I'm given a function public static int[][] resizeImage(int[][] original, int newWd, int newHt) and I'm supposed to use 2d arrays to map pixels from original to new image. Not sure if Im giving enough info. I dont want the answer, j...

Java Array - Calculate average of surrounding numbers

Ok, so I have an array like so: 1 2 3 4 5 6 7 8 9 Doesn't necessarily have to be any specific size, just showing it so you guys have something to look at. So I have to go through each number, and calculate the average of the numbers that are surrounding it. For example, for the number 1 I have to calculate the average of 2, 5, and 4....

Ruby array subtraction without removing items more than once

The canonical Array difference example in Ruby is: [ 1, 1, 2, 2, 3, 3, 4, 5 ] - [ 1, 2, 4 ] #=> [ 3, 3, 5 ] What's the best way to get the following behavior instead? [ 1, 1, 2, 2, 3, 3, 4, 5 ].subtract_once([ 1, 2, 4 ]) #=> [ 1, 2, 3, 3, 5 ] That is, only the first instance of each matching item in the second array is removed ...