sorting

Sorting a heterogeneous list of objects in Python

I have some custom objects and dictionaries that I want to sort. I want to sort both the objects the dictionaries together. I want to sort the objects by an attribute and the dictionaries by a key. object.name = 'Jack' d = {'name':'Jill'} sort_me =[object, d] How do I sort this list using the object's name attribute and the diction...

Sort lines on webpage using javascript/ regex

I'd like to write a Greasemonkey script that requires finding lines ending with a string ("copies.") & sorting those lines based on the number preceding that string. The page I'm looking to modify does not use tables unfortunately, just the br/ tag, so I assume that this will involve Regex: http://www.publishersweekly.com/article/CA659...

Java: Trouble with TreeSet and LinkedList

I have an unsorted linked list. To sort it, I thought I'd put the values into a TreeSet with a comparator supplied, then return those values as a new linked list. Yet, it fails. Comparator: public class SortSpeciesByCommonName implements Comparator<Species> { /** * a negative integer, zero, or a positive integer as the first ...

How can I sort a list when the sorting criterion requires an extra variable? C++

Hi there, this is for an assignment so I will be deliberately general. My question is related to implementation decisions I already made--maybe they weren't good ones. I have a list of pointers to structs, e.g. list<MyStruct*> bob; At one point I've needed to sort these pointers by one of the data members of their targets and I was able...

How to find k nearest neighbors to the median of n distinct numbers in O(n) time?

I can use the median of medians selection algorithm to find the median in O(n). Also, I know that after the algorithm is done, all the elements to the left of the median are less that the median and all the elements to the right are greater than the median. But how do I find the k nearest neighbors to the median in O(n) time? If the med...

Mix ascending and descending sorting in conditional sorting in MySQL

I have one table for two different kind of news. I want to create a list of them ordered by a date which depends of the type of news, so I tried this: SELECT * FROM my_table ORDER BY case type when 'news' then creation_date else 'events' then starting_date end desc; What I want is to sort news by c...

What is the difference between partition sort and quick sort?

What is the difference between partition sort and quick sort? ...

winforms datagridview sorting using LINQ

Hi there! Im using Linq...more specifically, PLINQO. anyway the following is an example of a query I have bound to a datagridview (winforms): public static List<Task> GetUserTasks( Guid userID ) { using (myDataContext ctx = new myDataContext()) { try { return ctx.Manager.Task.GetByUserID( userID ...

Sorting with MVCContrib

Does anyone know how to sort the MVCContrib grid when using a complex object. My grid is displaying a list of Person and I'm trying to sort on the Country property. The problem is that Country is a property an Address class which is a property of Person. Person.Address.Country <%Html.Grid(Model).Columns(column => { colum...

PHP pagination and sorting

I'm currently working on an in-house CMS and have come to a bit of a standstill. I'm trying to make it easy to paginate between pages of posts in a blog, and can't decide on how it should be tackled. The real problem only arises when I need to allow a user to choose how many results to display per page or the order to sort posts in. My ...

Quicksort not working

This is all my code for my quicksort method, it works on a set of 21 numbers, but not on my real data set, which is about 100000. I have no idea what is wrong, I've been fiddling for two hours and it is due soon! Any help would be very welcome public static void hybridQuicksort( int[] a, int start, int end ) { final int MIN = 13; if (...

How do you get a directory listing sorted by creation date in PHP?

Hi, I have to list directories by using scandir() function but result array should be sorted according to date and time of directory created. Regards Deepak ...

Unix Sort with U

Anyone knows how this sort works? What do they [+0.2 -0.42 +0.0 -0.1 -o] mean? CmdString.Format("sort -u +0.2 -0.42 +0.0 -0.1 -o %s %s", (const char *)TempFilename, (const char *)TempFilename); ...

How to compute the absolute minimum amount of changes to convert one sortorder into another?

Goal How to encode the data that describes how to re-order a static list from a one order to another order using the minimum amount of data possible? I have a feeling there is an algorithm or computer science term that will help me but right now I'm too stuck on the problem to figure out other ways of looking at it. Background Motivat...

How do I sort one vector based on values of another

I have a vector x, that I would like to sort based on the order of values in vector y. The two vectors are not of the same length. x <- c(2, 2, 3, 4, 1, 4, 4, 3, 3) y <- c(4, 2, 1, 3) The expected result would be: [1] 4 4 4 2 2 1 3 3 3 ...

Arrange numbers in ascending order using if and swap statement

How can I arrange numbers in ascending order using if and swap statements? Could someone give me some direction? ...

Sort php array on one column and output to list

I have created an array that is populated from a wordpress loop:- <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?> $alisting []["questions"] = $questions; $alisting []["id"] = $post->ID; $alisting []["title"] = $post->post_title; <?php endwhile; ?> This outputs Array ( [0] => Array ( [quest...

std::unique analogue in Qt?

I have browsed the documentation, but didn't find one. Any ideas? ...

Comparison Delegate flip flops results on identical keys

Is there any way to get consistent results from Comparison when some of the sort items are the same? Do I just have to code up my own sort routine? public class Sorter { public void SortIt() { var myData = new List<SortData>(3); myData.Add(new SortData { SortBy = 1, Data = "D1"}); myData.Add(new So...

Problem with Berkeley DB and C++

I'm trying to write a simple C++ program that uses Berkeley DB for storage. The key of the database is of type time_t and the data is an integer. I need to take the difference between two adjacent data in a between two key. I open a cursor with the flag DB_SET_RANGE and then i use DB_NEXT to iterate. My problem is that the cursor retur...