sorting

PHP sort multidimensional array with primary & secondary keys

How do you sort a multidimensional array by primary and secondary key? For example, assuming the following array: $result = array(); $result[0]["prio"] = 1; $result[0]["date"] = '2010-02-28'; $result[0]["post"] = "February's thoughts"; $result[1]["prio"] = 0; $result[1]["date"] = '2010-04-20'; $result[1]["post"] = "April's thoughts"; ...

Which parallel sorting algorithm has the best average case performance?

Sorting takes O(n log n) in the serial case. If we have O(n) processors we would hope for a linear speedup. O(log n) parallel algorithms exist but they have a very high constant. They also aren't applicable on commodity hardware which doesn't have anywhere near O(n) processors. With p processors, reasonable algorithms should take O(n/p l...

Problem with sorting list

I have a problem with sorting collection. User saves few values and he sorts it. At next launch program must order a new collection. Values which have been saved by user can be in new collection, but It can be situation , when those values aren't in new collection. I wrote some code, and I want your feedback If it has sense var ol...

Quickly sorting an array of objects based on their known resemblance to each other using C

I have a randomly ordered C array of integer numbers. Each of these numbers represents a color, and has its relationship to every other number in the array defined elsewhere (they are non-linear, and are based on both the brightness of the color and the hue). I need a quick, efficient algorithm to sort these numbers based on their ...

why does the uniq! method work but sort! not on this array in rails?

Here is how I created an array: @companies_with_email = Company.contact_emails_date_sent_gt(@monday). contact_emails_date_sent_lt(@friday). find(:all, :select => "distinct companies.* ") || [] @companies_with_call = Company.contact_calls_date_sent_gt(@monday). ...

Two questions about my SQL script. How to add subtotal/total lines, and a sorting issue.

I have some T-SQL that generates a nice report giving a summary some stuff by month. I have 2 questions, is there a way to get the to sort the months by calendar order, not by alpha? And, what i would like to do is add a total line for each year, and a total line for the whole report? SELECT CASE WHEN tmpActivity.Year IS NULL THEN...

problem in sorting image-wise

Hi there, I have a table in which there are fields like user name, name, age, activity. In this if new user is added then an image is shown beside that user name. Until now sorting was done by activity by default, but I want all the newly added users to be shown first in the table by default, how can i sort in this case? Any hint? ...

How can I list all files in a directory sorted alphabetically using PHP?

I'm using the following PHP code to list all files and folders under the current directory: <?php $dirname = "."; $dir = opendir($dirname); ?> <?php while(false != ($file = readdir($dir))) { if(($file != ".") and ($file != "..") and ($file != "index.php")) { echo("<a href='$file'>$file</a> <br />"); } } ?> The problem is list is not ...

Sort first n integers in linear time and constant space

I'm looking for a non-comparison or comparison based algorithm that can sort an array containing any permutation of the first n positive integers, which should be O(n) time complexity and O(1) space complexity. Is there an existing algorithm that fits these specifications? ...

python: how to sort a complex list on two different keys

I have a weird list built in the following way: [[name_d, 5], [name_e, 10], [name_a, 5]] and I want to sort it first by the number (desc) and then, if the number is the same, by the name (asc). So the result I would like to have is: [[name_e, 10], [name_a, 5], [name_d, 5]] I tried to think to a lambda function that I can use in t...

Sorting Algorithm 2

An in-place algorithm with O(n) running time that rearranges an unsorted array A[0 . . . n − 1] filled with distinct integers so that, for a given k (1<=k<=n), A[0 . . . k − 1] contains the k smallest integers in increasing order. Is there an existing algorithm that meets these specifications, or one that can be altered to meet them, I ...

In-place sorting algorithm for the k smallest integers in an array on n distinct integers

Is there an in-place algorithm to arrange the k smallest integers in an array of n distinct integers with 1<=k<=n? I believe counting sort can be modified for this, but I can't seem to figure out how? Any help will be appreciated. ...

Sort By Soundex (or similar) `Closeness`

Is there any way to have MySQL order results by how close they 'sound' to a search term? I'm trying to order fields that contain user input of city names. Variations and misspellings exist, and I'd like to show the 'closest' matches at the top. I know soundex may not be the best algorithm for this, but if it (or another method) could b...

Selection Sort - Stack Overflow

Hi I am trying to implement Selection Sort in vb.net using recursion. Problem is that I keep getting stackoverflow if the array I want to sort is 1000 elements. I can't find the problem. I don't know much about stack overflow or how to check it. From my research the problem could be infinite recursion but I check for that and exit the su...

Dynamic LINQ help for sorting problem

I have a simple IEnumerable collection of Order objects. I want to write a generic sort function that accepts the collection and a sortkey that corresponds to a property on an Order object. I don't want to hardcode the sort instructions for every property. How can I build a dynamic LINQ string that automatically generates the LINQ for me...

Trying to sort an array.

I'm trying to sort an array least to greatest and i am really lost.... Here is what i have so far: int temp, temp2; for (int x = 0; x < array_size; x++) { temp=a[x]; for (int i = 0; i < array_size; i++) { if (a[i] < temp) { temp2=a[i]; ...

Use JavaScript to highlight the sorted column of a dynamically sorted table.

I am using the JS from this link for sorting my tables but this JS is not highlighting the selected column. I'm not very much into JavaScript that's why i want help to do that. What i need is that on clicking the heading of the column that has to be sorted the whole column should get highlighted with the sorted data. Please help me to ...

Sort an array which is partially sorted

I am trying to sort an array which has properties like it increases upto some extent then it starts decreasing, then increases and then decreases and so on. Is there any algorithm which can sort this in less then nlog(n) complexity by making use of it being partially ordered? array example = 14,19,34,56,36,22,20,7,45,56,50,32,31,45.......

How to disable the sorting click on table header when server side data is still processing?

Hi All, I'm doing the server side sorting in datatable plugin .Data takes 4-5 seconds to load, in the mean time if the user clicks on other headers it will again trigger the ajax call. Please help me on how to restrict the user when the servers side data is still in processing state. Is there any initial function where i can check custom...

how to sort this list?

I have a String list ArrayList<String> list = new ArrayList<String>(); with each item: list.add(week+" "+year); where week and year are integers. How to sort this list to ascending order? ...