arrays

Sort Ascending or Descending inside a Bubble-Sort

After this was answered I continued to work my way through the code. It work's perfect this way: static String[][] bubbleSort(String customerdata[][], int sortafter, int asc) { String temp []; boolean sort; do{ sortiert = true; for (int i = 0 ; i < customerdata.length - 1; i++){ if(customerdata[i][sortafter].compa...

How do I efficiently reject Strings in an array if they (regex) match Strings in a second array in Ruby?

I have two arrays of Strings, for example sentences and words. If any word is found in a sentence e.g. sentence =~ /#{word}/ I want to reject the sentence from the sentence array. This is easy to do with a double loop, but I'm wondering if there is a more efficient way of doing this, maybe with logical operators? ...

Problem searching a Binary Search Tree - Array Based

I am trying to search for a word using a key value recursively. In retrieve function: Problem is the index goes from 0, 1,3,7, to 15.... it suppose to go 0,1,3,7,8 and so forth I have the insert working as expected. I have the inorder, preorders, all working. Can someone please help me figure out this problem? I have been working on this...

How to create an integer array in Python?

It should not be so hard. I mean in C, int a[10]; is all you need. How to create an array of all zeros for a random size. I know the zeros() function in NumPy but there must be an easy way built-in, not another module. ...

Extension method for fill rectangular array in C#

I want write extension method for fill multidimensional rectangular array. I know how to do it for the array with a fixed number of measurements: public static void Fill<T>(this T[] source, T value) { for (int i = 0; i < source.Length; i++) source[i] = value; } public static void Fill<T>(this T[,] source, T value) { for ...

A C++ library for Arrays, Matrix, Vector, and classical linear algebra operations

Which library do you use for N-dimensional arrays? I use blitz++ at work and I really dislike some aspect of it. Some aspect of it are even dangerous. The need for resizing before using operator=. A(Range::all(), Range::all()) throws for an (0,0) matrix, etc. and the linear algebra operations are to be done via clapack. I used and lov...

Interleaving multiple arrays into a single array

I need to merge several arrays into a single array. The best way to describe what I'm looking for is "interleaving" the arrays into a single array. For example take item one from array #1 and append to the final array. Get item one from array #2 and append to the final array. Get item two from array #1 and append...etc. The final a...

sql COUNT function returns an array instead of mysqli object?

I want to count some rows in my database and I'm using the following code: $tagname = Person; $query = "SELECT COUNT(thread_tag_map.tag_id) AS tagcount FROM tags, thread_tag_map WHERE thread_tag_map.tag_id = tags.id AND tags.name = '$...

convert integer to array, c++

I would like to convert an integer into an array, so that it looks like the following: int number = 123456 ; int array[7] ; with the result: array[0] = 1 array[1] = 2 ... array[6] = 6 ...

Reading a file line by line in C

Hello, I am trying to write some code that will open a file, read its content line by line and store each of these lines into an array. First I open the file and count the number of lines, each of the lines is of a fixed length so I simply do this : char buf2[LINE_LENGTH]; int in2 = open("toSend2", O_RDONLY); int number_o...

add key => value to an associative array in a loop?

while($tag = mysqli_fetch_assoc($result)) { $arrayresult[$tag['id']][$tag['name']] = $tag['count']; } the $result contains 4 rows from database table. i want it to be like: $arrayresult[1]['mac'] = 34 $arrayresult[22]['pc'] = 32 $arrayresult[31]['windows'] = 14 $arrayresult[4]['linux'] = 23 the code above doesnt seems to work...

Marshal struct problem with C#

I'm usign C# with P/Invoke to acces to a dll method. The definition of the method is the following: [DllImport("userManager.dll")] static extern int GetUsers(out IntPtr userList); And the struct layout I've done is the following: [StructLayout(LayoutKind.Sequential)] public class USER_LIST { public uint NumUsers; ...

php multi-dimensional array remove duplicate

Not sure if this question is a duplicate in need of removal, but I couldn't find the answer elsewhere so I'll have a go at asking. I've got a 2d array that looks as follows: Array ( [0] => Array ( [0] => dave [1] => jones [2] => [email protected] ) [1] => Array ( [0] => john [1] => jones ...

convert values in string to float array

i have a string in C which i got from some algorithm. it has numeric values in a format like this 0.100 0.840 0.030 0.460 0.760 -0.090 and so on in need to store each of these numeric values into a float array for numeric processing. i am new to C and found string handling in C to be complex. can anyone tell me how i might implement ...

PHP Clean Up Permutated Array

Hey all, basically, i have an array: array('a', 'b', 'c'); Now i run it through an array permutation function and the result is: Array ( [0] => Array ( [0] => C ) [1] => Array ( [0] => B ) [2] => Array ( [0] => B [1] => C ) ...

How to set url parameters in an array?

Hey guys I am using open id authentication on my website and after authenticating I am getting a url from openid providers i.e yahoo and google http://www.mysite.com/openid-login.php? openid.identity=https://me.yahoo.com/a/1234567&amp; openid.ax.value.nickname=john& [email protected]& http://www.mysite.com/openid-...

why a[n] is accepted in c during runtime?

why can we do this in c? int n; scanf("%d",&n); int a[n]; I thought array is located memory during load time but seems like the above example works during runtime. Do I misunderstand any thing? can you guys help? Thanks, ...

C# how to write long type array to binary file

i have a long type array. How to write this array to binary file. Problem is that if i convert it into byte array some values are changed. The array is like- long array = new long[160000]; Give some code snippet. ...

How can I sum arrays element-wise in Perl?

Hi. I have two arrays: @arr1 = ( 1, 0, 0, 0, 1 ); @arr2 = ( 1, 1, 0, 1, 1 ); I want to sum items of both arrays to get new one like ( 2, 1, 0, 1, 2 ); Can I do it without looping through arrays? ...

javascript - loop multidimesntional array

I am sure this is really simple, I used to have a function for checking the contents of an array. Now Id like to modify it to check a two dimensional array. function ChkArray(Str, Val){ for (var i=0;i<Str.length;i++){ if (Str[i] == Val) {return i;} } return -1; } My new attempt: function ChkArray2(Str, Val){ for (var i=...