sorting

MySql conditional order by

I have this table (simplified): CREATE TABLE `my_table` ( `id` INT NOT NULL AUTO_INCREMENT , `item_name` VARCHAR(45) NULL , `price` DECIMAL(10,0) NULL , PRIMARY KEY (`id`) ) I need to select all items from the table, ordered this way: 1. items with price > 0.00 first, ordered by price ASC 2. items with price = 0.00 last, orde...

(When) are parallel sorts practical and how do you write an efficient one?

I'm working on a parallelization library for the D programming language. Now that I'm pretty happy with the basic primitives (parallel foreach, map, reduce and tasks/futures), I'm starting to think about some higher level parallel algorithms. Among the more obvious candidates for parallelization is sorting. My first question is, are p...

Sort a string list: Move or exchange items only

In Delphi / Pascal I would like to sort a TStringList alphabetically. But for this purpose, I can only use the following two methods: Move: Moves a string from one index position to another, shifting other strings around as appropriate. Exchange: Swaps two strings in the list, as identified by their index positions. How could I do thi...

Playlist for music player in Delphi / List of multiple data items

I would like to have a playlist for my own music player in Delphi / Pascal. I thought that it would be the best solution to have a TStringList with the path of the MP3 file and - additionally - a TListBox with the song names. The matching strings in both lists must be at the same position. So if the user chooses item 5 in TListBox I can...

NSDictionary - Printing Array

Hi, This site is great I'm getting alot of replies , so I have tried to code what I had problems with before here it is NSMutableArray *sort = [NSMutableArray arraywithArray:[dic allValues]]; for(NSString *s in sort){ [Purchases appendString:[NSString stringWithFormat:@"%@",s]]; } textview.text = Purchases; The output's ord...

load javascript effects after ajax (js column sort for example)

I've found several js table column sorters that work great on regular html content: http://www.kryogenix.org/code/browser/sorttable/ http://www.allmyscripts.com/Table_Sort/index.html#how_to_use_it The first one works by assigning a class to a table. The second by passing the id of the table to a js constructor. I'm using jQuery to ha...

How can I create 'teams' from a list of weighted 'users' randomly but fairly using PHP?

What I am hoping to achieve is the ability to generate 'teams' of users. I will have x amount of men, weighted (decimal skill weight, like 75.23) and y amount of women (also with a skill weight value). Given that list of users, I would then take for input the number of teams to make (let us say, 6 teams). Then, I go through the list o...

Adobe Flex Flash Builder DataGrid dataProvider CollectionEvent.COLLECTION_CHANGE handler's access to DataGrid?

I've added an eventListener to the COLLECTION_CHANGE event that is fired when the grid is finished resorting the items in its dataProvider, after the user clicks on a column header: MyType (myDataGrid.dataProvider).addEventListener(CollectionEvent.COLLECTION_CHANGE, onDataGridResort); ... private function onDataGridResort(e:...

SQL Sorting Data into a Pattern

Not sure if this is possible, but there might be a creative approach... Given this data in SQL Server 2005: AAA AAA BBB BBB CCC CCC DDD DDD How could I return a result set sorted in a pattern like this: AAA BBB CCC DDD AAA BBB CCC DDD ...

How sort elements and store them in a variable, XSLT

Hello everyone, I was wondering whether it's possible to sort some elements first and store them (already sorted) in a varible. I would need to refer to them thought XSLT that's why I'd like to store them in a variable. I was trying to do the following, but it doesn't seem to work <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/...

ICollectionView.SortDescriptions does not work for boolean

Hi ! myListBox.Items.SortDescriptions.Add( new SortDescription("BoolProperty", ListSortDirection.Descending)); This sorting works only for string properties of the underlying project. Not with boolean? Is there a reason for that ? Thanks ! UPDATE: Yep, your example really works. But what's wrong on my example ? public clas...

Python: sort a part of a list, in place

Let's say we have a list: a = [4, 8, 1, 7, 3, 0, 5, 2, 6, 9] Now, a.sort() will sort the list in place. What if we want to sort only a part of the list, still in place? In C++ we could write: int array = { 4, 8, 1, 7, 3, 0, 5, 2, 6, 9 }; int * ptr = array; std::sort( ptr + 1, ptr + 4 ); Is there a similar way in Python? ...

Sorting a combobox purely in XAML

I'm surprised that no one has asked this before here... well, at least I haven't found an answer here or anywhere else, actually. I have a ComboBox that is databound to an ObservableCollection. Everything worked great until the guys wanted the contents sorted. No problem -- I end up changing the simple property out: public Observable...

Django Sort By Calculated Field

Using the distance logic from this SO post, I'm getting back a properly-filtered set of objects with this code: class LocationManager(models.Manager): def nearby_locations(self, latitude, longitude, radius, max_results=100, use_miles=True): if use_miles: distance_unit = 3959 else: distance_uni...

Simple, fast SQL queries for flat files.

Does anyone know of any tools to provide simple, fast queries of flat files using a SQL-like declarative query language? I'd rather not pay the overhead of loading the file into a DB since the input data is typically thrown out almost immediately after the query is run. Consider the data file, "animals.txt": dog 15 cat 20 dog 10 cat 3...

Using STL algorithms (specifically std::sort) from within a templated class

I've declared a template class MyContainer as bellow, then created an instance of it of type DataType1. The DataType1 class provides a friend function "DataSpecificComparison" which is used by std::sort to compare DataType1 objects. The program compiled and sorted correctly. I then defined a class called DataType2, gave it a friend imp...

Reversing words in a string

Hello, does anybody know how can I sort words in string using javascript, jquery. For example I have this: var words = "1 3 2" Now I want to reverse it to this: var words = "2 3 1" Thanks ...

Merging two lists into one and sorting the items.

Is there a way to merge(union without dupes) two given lists into one and store the items in sorted way by using ONE for loop? Also, i am looking for a solution which does not makes use of API methods ( like, union, sort etc). Sample Code. private static void MergeAndOrder() { var listOne = new List<int> {3, 4, 1, 2, 7, 6, 9, 11}; ...

Selective ordering with LINQ, partial ordering

Let's say I have a list of objects: var items = new { new { Order = 0 }, new { Order = 1 }, new { Order = -1 }, new { Order = 3 }, new { Order = 2 }, new { Order = -1 } }; I need to order it so that items with "Order > -1" be on top of the list ordered by Order ascending, and remaining items with "Order == -1" ...

PHP array multiple sort - by value then by key?

I have an array of string keys with numeric values for use in a list of tags with the number of occurances of each tag, thus: $arrTags['mango'] = 2; $arrTags['orange'] = 4; $arrTags['apple'] = 2; $arrTags['banana'] = 3; this is so i can display the tag list in descending occurance order thus: orange (4) banana (3) mango (2) apple (2) ...