I have an operation on a heap, a fixdown operation . This is the code:
public class Heap {
public static void fixdown (int a[],int k,int n) {
while (2*k<=n) {
int j=2*k;
if (j<n && a[j]<a[j+1]) j++;
if (!(a[k]<a[j])) break;
swap(a,k,j);
k=j;
}
}
...
I want to build a hierarchy from a one-dimensional array and can (almost) do so with a more or less hardcoded code. How can I make the code dynamic?
Perhaps with while(isset($array[$key])) { ... }?
Or, with an extra function? Like this: $out = my_extra_traverse_function($array,$key);
function array_traverse($array,$key=NULL) {
$out...
Is there any fast way to flatten an array and select subkeys ('key'&'value' in this case) without running a foreach loop, or is the foreach always the fastest way?
Array
(
[0] => Array
(
[key] => string
[value] => a simple string
[cas] => 0
)
[1] => Array
(
...
I have 2 arrays named Arr1 and Arr2 in C#.
They are of the exact same dimensions...
I need to get the element of Arr1 corresponding to maximum of elements in Arr2 beginning with given indices ...
e.g
Get indices of the max of Arr2 [ 1 , 10 , 3 , i , j ] for all i,j
Return Arr1 [ 1 , 10 , 3 , i , j ]
Of course I need the elegant sol...
OK so the array is not working.
My code: http://www.javadan.pastebin.com/C9QiVySe
I am trying to check if blocked(lastX,lastY) of the following tile he is on. I count the tile the player is standing on by adding or minusing X and Y when they go up, down, left, or right. So if the player starts at 0,0, they press down twice and right on...
I have two arrays. I need to check and see if the elements of one appear in the other one.
Is there a more efficient way to do it than nested loops? I have a few thousand elements in each and need to run the program frequently.
-Alex
...
Hi.
I have this array (JQuery) where I add all my form's controls, it looks like:
var name = $("#name"),
surname = $("#surname"),
address = $("#address"),
phone = $("#phone"),
photo = $("#photo"),
grade = $("#grade"),
profession = $("#profession"),
e...
If a binary search requires an array to be sorted before hand, why does the following code work?
string[] strings = new[] { "z", "a", "y", "e", "v", "u" };
int pos = Array.BinarySearch(strings, "Y", StringComparer.OrdinalIgnoreCase);
Console.WriteLine(pos);
And why does this code result return -1?
public class Person : IC...
I want to create an array of Dictionaries. But the array size is unknown. For integer, i used List to obtain the integer array of unknown size. But in the case of Dictionary, am not able to create a list of Dictionary. Is thr any wayz by which this can be done? Dictionary(int, String) paramList=null;I am want to create the array of param...
These static Array methods have me puzzled. They seem to do the same things. Are they available for older legacy code?
Array.IndexOf
Array.FindIndex
Array.LastIndexOf
Array.FindLastIndex
...
Hi guys,
let's assume I've got the address of my array (passed as a pointer to the function) in esi register. How can I access a particular cell of the array? i.e:
my_array[a + b * c]
where c is constant.
Thank you for the fast reply!
Cheers
...
Hello,
I have a field in my DB that holds value separated by commas like;
$tmp_list = "COB,ISJ,NSJ,"
Now when I fetch that the row, I would like to have them in an array.
I have used array($tmp_list) but I get the values in one line only like:
[0] => 'COB,ISJ,NSJ,'
instead of
[0] => 'COB',
[1] => 'ISJ',
[2] => 'NSJ'
All help i...
For an algorithm I'm working on I tried to develop a blacklisting mechanism that can blacklist arrays in a specific way: If "1, 2, 3" is blacklisted "1, 2, 3, 4, 5" is also considered blacklisted.
I'm quite happy with the solution I've come up with so far. But there seem to be some serious problems when I access a blacklist from multiple...
How can I compare the first letter of the first element of a char**?
I have tried:
int main()
{
char** command = NULL;
while (true)
{
fgets(line, MAX_COMMAND_LEN, stdin);
parse_command(line, command);
exec_command(command);
}
}
void parse_command(char* line, char** command)
{
int n_args = 0,...
I'm setting out to create a settings activity for my app. I've defined a PreferenceActivity with a nice layout including a ListPreference object for the user to select a bluetooth device. I'm having trouble dynamically populating the list.
I would like to populate ListPreference with values from an array adapter (which I'll create and p...
I'm working with the latest draft of the twitter annotations api. An example bit of data looks like
status {
annotations : [
{myAnnotationType:{myKey:myValue}},
{someoneElsesAnnotationType:{theirKey:theirValue}},
]
}
now i want to check a status to see if it has an annotation with myAnnotationType in it. I...
Hello guys
I would like to know how to compare two two-dimension arrays value.
First array
Array 1
(
[0] => Array
(
[0] => a
)
[1] => Array
(
[0] => b
)
[2] => Array
(
[0] => c
)
}
Second one
Array 2
(
[0] => Array
...
So I need to have an array of structs in a game I'm making - but I don't want to limit the array to a fixed size. I'm told there is a way to use realloc to make the array bigger when it needs to, but can't find any working examples of this.
Could someone please show me how to do this?
Thanks!
...
$query = $this->db->query("SELECT t1.numberofbets, t1.profit, t2.seven_profit, t3.28profit, user.user_id, username, password, email, balance, user.date_added, activation_code, activated FROM user LEFT JOIN (SELECT user_id, SUM(amount_won) AS profit, count(tip_id) AS numberofbets FROM tip GROUP BY user_id) as t1 ON user.user_id = t1.user_...
How can I search a dynamic array of char in Delphi 6 for a sub-string and get back an index to a match, not a pointer? I've seen functions in Delphi 6 that do this for strings but not for dynamic char arrays. There is a function called SearchBuf but that function returns a PChar pointer to the match location when what I need is the arr...