sorting

Data structures: Which should I use for these conditions?

This shouldn't be a difficult question, but I'd just like someone to bounce it off of before I continue. I simply need to decide what data structure to use based on these expected activities: Will need to frequently iterate through in sorted order (starting at the head). Will need to remove/restore arbitrary elements from the/a sorted...

sorting lists of lists in haskell

i'm completely stumped on how to Write a function that, given a list of sets returns the sets split into sublists by size (and with the sublists ordered by the size of sets they contain). sample input *Main> allSets [[1,2],[8],[1,4,7,8],[5],[1,4],[1],[2,3],[1,2,5,8],[3,4,6,7],[1,2,3,4],[4],[5,6,7,8],[3,4],[3],[2,3,5,6],[7],[6],[2]] sam...

Most efficient way to sort two vectors in lockstep in R?

What's the most efficient way to sort two vectors in lockstep in R? The first vector should be sorted in ascending order and the second should be reordered in lockstep such that elements with corresponding indices before the sort still have corresponding indices after the sort. For example: foo <- c(1,3,2, 5,4) bar <- c(2,6,4,10,8) so...

C#: How to order arrays in a predefined custom order by only the first 4 digits?

I want to do this with a simple text box GUI for folks to paste into and re-copy. For example if it started like this: Before part # QTY CS01-111-111 3 CS02-222-222 3 CS03-333-111 3 CS03-333-333 3 I'd like textBox1.text to sort anything pasted into it like this going by the first 4 digits only, but retaining the QTY ...

Sorting in jqGrid?

Hello All, I am binding the jqgrid but the sorting is not working plaese can anyone tell why it is not working.I am posting the code here jQuery(document).ready(function() { var TheGrid; var resp; jQuery("#registerUsers").jqGrid( { url: 'EventsList.aspx', da...

Flex custom sorting capabilities with server side support

The sorting capabilities that are available in Flex assume that you have access to all the data, but I'm using a paginated datagrid (with custom code), the datagrid is binded to an ArrayCollection instance, on the next page call I change the data of the dataprovider and everything works ok, but for sorting I need to override the click or...

What's a good way of *temporarily* sorting a vector?

Hi, I've got a std::vector which I need to sort by selected algorithms for certain operations, but to maintain its original state (e.g. items ordered by when they were entered) the rest of the time. Obviously I can use std::copy to create a temporary vector and sort that, but I'm wondering if there's a better way, possibly by timestamp...

filter and sort list using google collections.

Suppose I have a list (or Set): List<String> testList = Lists.newArrayList("assocX","srcT","destA","srcX", "don't care Y", "garbage", "srcB"); I would like to get back an ImmutableList(Set) that sorts/groups terms in natural order where terms that begin with "src" are first, "assoc" second and "dest" last. If a term does not contain ...

How can I get the number of instances of a value in a Rails array?

Say I have an array like this: ["white", "red", "blue", "red", "white", "green", "red", "blue", "white", "orange"] I want to go through the array and create a new array containing each individual color and the amount of times it appeared in the original array. So, in the new array it would report that "white" appeared 3 times, "blu...

What is a Deterministic Quicksort?

I have been reading about Quicksort and found that sometimes it' s referred to as "Deterministic Quicksort". Is this an alternate version of the normal Quicksort ? What is the difference between a normal Quicksort and a Deterministic Quicksort ? ...

Jasper Reports crosstab sorting with comparatorExpression

I'm trying to sort my dynamic columns in a cross tab according to some custom scheme. In the docs I found mention of comparatorExpression: Crosstab group bucket comparator expression. The result of this expression is used to sort the buckets, in ascending or descending order. If no comparator expression is specified, the natural order...

How to sort a collection of objects by an variable they all hold?

I have a class named Individual, which has a variable, self.fitness. I have a collection of these Individual instances and I'd like to sort them by their fitness. How is this done in python? ...

How do you sort (alphabetically by keys) a $_POST request in PHP.

I'm looking at http://www.php.net/manual/en/array.sorting.php as a reference. I'm trying to sort the $_POST by the keys. This is what I am trying, but it only prints "1". What else needs to happen, or what is missing? Thank. <?php $data = krsort($_POST); print_r( $data ); ?> ...

How can i sort java JTable with an empty Row and force the Empty row always be last?

I am using JTable with an empty row at the bottom of the table in order to give the ability of adding new line to the table. After insert or writing data in the empty row i am adding automtacly a new empty row below it. (It suppose to act like the Microsoft visual tables) I am using the java default row sorter, The problem is that i n...

Modifying this Quicksort to always use the the last element as the pivot

I have the following Quicksort that always chooses the first element of the subsequence as its pivot: void qqsort(int array[], int start, int end) { int i = start; // index of left-to-right scan int k = end; // index of right-to-left scan if (end - start >= 1) { // check that there are at least two elements to sort ...

Sort NameValueCollection against Enum

I have to sort a namevaluecollection(Items usually 5 to 15) Against an enum(having items more than 60). Right now I am using this extension function, Anyone have better idea to write this code.... public static NameValueCollection Sort(this NameValueCollection queryString, Type orderByEnumType, bool excludeZeroValues) { ...

Sorting a table physically in Delphi

Delphi does not seem to like multi-field indexes. How do I physically sort a a table so that I wind up with a table that has the rows in the desired order? Example: mytable.dbf Field Field-Name Field-Type Size 0 Payer Character 35 1 Payee Character 35 2 PayDate Date 3 Amount ...

Sort a list from Arrays.asList() changes also the origin array ?

Hi all, I noticed a strange behavior (for me) when sorting a list retrieved with Arrays.asList(). It seems that after Collections.sort( list ), the origin array is also sorted ! How is it possible ? List<Rate> rates = Arrays.asList( arrayRates ); Collections.sort( rates, new RateEffectiveDateComparator() ); /* after that the rates lis...

How can I define a "Do-Nothing" sort?

Hi, I'm working on a system where I need to be able to sort a vector by a given predicate, which my classes shouldn't have control over. Basically, I pass them a derived class and they blindly sort on it. As one of the "delightful quirks", one of the sort patterns is order of entry. Here's what I've got so far. struct Strategy { vi...

Sort array with recursive function call?

I need the following array in alphabetical order (at all levels), but asort doesn't seem to work because I have a recursive call in my function (or so I think); it only partially sorts my array, so I'll have chunks of it that are alphabetized, but they'll be out of order. Help! Ex. Directory Listing: apartments.html js/ application....