Questions tagged [sorting]

Sorting is the process of applying some order to a collection of items.

Sorting is the process of applying some order to a collection of items. There are various for doing this, including , , and .

From the Sorting Algorithms Wikipedia entry:

In a is an algorithm that puts elements of a list in a certain order. The most-used orders are order and order. Efficient sorting is important for optimizing the use of other algorithms (such as search and merge algorithms) that require sorted lists to work correctly; it is also often useful for data and for producing human-readable . More formally, the output must satisfy two conditions:

  1. The output is in nondecreasing order (each element is no smaller than the previous element according to the desired total order);
  2. The output is a permutation (reordering) of the input.

Related tags:

67842 questions
14
votes
1 answer

DataGridView Using SortableBindingList

I have a function that returns an IList< T > and is the DataSource for a DataGridView. I learned that DataGridView won't sort IList. I read This stackoverflow Q&A and am trying to implement SortableBindingList. I must be doing something wrong…
waltmagic
  • 604
  • 2
  • 7
  • 22
14
votes
4 answers

Chinese Sorting by Pinyin in Javascript with localeCompare?

I am facing quite a challenge here. I am to sort certain Chinese "expressions" by pinyin. The question: How could I sort by pinyin in Firefox? Is there a way to sort properly in IE 9 and 10? (They are also to be supported by the…
Daniel V.
  • 868
  • 7
  • 14
14
votes
8 answers

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…
plinehan
  • 649
  • 6
  • 15
14
votes
4 answers

Sorting a nested OrderedDict by key, recursively

Say orig is an OrderedDict which contains normal string:string key value pairs, but sometimes the value could be another, nested OrderedDict. I want to sort orig by key, alphabetically (ascending), and do it recursively. Rules: Assume key strings…
tester
  • 20,193
  • 21
  • 80
  • 120
14
votes
5 answers

Reorder four points of a rectangle to the correct order

The aspect-ratio=height/width is always >1 (for most cases even >2), so it should be clear/precise how I'd like to rotate. I have a RotatedRect object in OpenCV / Java. I can get an Array of it with 4 Objects of Type Point and Point defines…
tim
  • 8,782
  • 15
  • 70
  • 127
14
votes
2 answers

QuickSort Dijkstra 3-Way Partitioning: why the extra swapping?

Given the algorithm here, look at the scenario where i is at "X", the following happens: Scenario: i -> "X", "X" > "P" 1. swap("X", "Z"), gt--; // the value at i is now "Z", which is still > "P" 2. swap("Z", "Y"), gt--; // the value at i is now…
Joshua Kissoon
  • 3,155
  • 5
  • 26
  • 57
14
votes
3 answers

How can I get TStringList to sort differently in Delphi

I have a simple TStringList. I do a TStringList.Sort on it. Then I notice that the underscore "_" sorts before the capital letter "A". This was in contrast to a third party package that was sorting the same text and sorted _ after A. According to…
lkessler
  • 19,414
  • 31
  • 125
  • 196
14
votes
3 answers

Sort Dictionary (string, int) by value

So basically I'm having an issue with the task I've been given. I won't bore you with the details of the task itself so I'll just give you the relevant info. I have a dictionary that I need to be sorted by the int[value] that is the highest, well…
Zain
  • 1,106
  • 4
  • 12
  • 26
14
votes
5 answers

How to simulate "sort -V" on Mac OSX

I have written a bash script that I need to work identically on linux and mac osx that relies on the sort command. I am piping the output of git tag -l to sort to get a list of all the version tags in the correct semantic order. GNU offers -V which…
sphoid
  • 535
  • 7
  • 18
14
votes
2 answers

How to sort,uniq and display line that appear more than X times

I have a file like this: 80.13.178.2 80.13.178.2 80.13.178.2 80.13.178.2 80.13.178.1 80.13.178.3 80.13.178.3 80.13.178.3 80.13.178.4 80.13.178.4 80.13.178.7 I need to display unique entries for repeated line (similar to uniq -d) but only entries…
Andrew Kennen
  • 143
  • 1
  • 6
14
votes
3 answers

PHP array_merge if not empty

Trying to merge 4 arrays, but some may be empty at certain times. $array_1 = array('something1', something2); $array_2 = array('something3', something4); $array_3 = array(); $array_4 = array('something1', something2); $list =…
David
  • 1,716
  • 3
  • 26
  • 45
14
votes
5 answers

Tk treeview column sort

Is there a way to sort the entries in a Tk Treeview by clicking the column? Surprisingly, I could not find any documentation/tutorial for this.
Sridhar Ratnakumar
  • 68,948
  • 61
  • 139
  • 172
14
votes
2 answers

Sorting in python - how to sort a list containing alphanumeric values?

I have a list that consists of details like this: list1 = ["1", "100A", "342B", "2C", "132", "36", "302F"] now, i want to sort this list, such that the values are in the following order: list1 = ["1", "2C", "36", "100A", "132", "302F",…
Randomly Named User
  • 1,779
  • 7
  • 25
  • 44
14
votes
4 answers

Rails, how to sort the array of active records by created_at

Hi there I have two arrays having different values of active records from same table but having different values, I want to combine them both and then sort them by created_at, but not getting any clue, I am stuck. Please help. Here is my…
Lakhan
  • 145
  • 1
  • 1
  • 8
14
votes
9 answers

Java How to return top 10 items based on value in a HashMap

So I am very new to Java and as such I'm fighting my way through an exercise, converting one of my Python programs to Java. I have run into an issue where I am trying to replicate the behavior, from python the following will return only the keys…
Eric
  • 590
  • 2
  • 6
  • 18
1 2 3
99
100