sorting

sorting part of a multidimensional array

I have an multi dimensional array: $array[0] = array ( name => "Bob", position => "Chair", email => "[email protected]" ); $array[1] = array ( name => "Al", position => "", email => "[email protected]" ); //etc.. I want to sort it so that those whose position != "" are first, then the rest alphabetically by name... I'm not very fam...

Stable Sorting, ie, Minimally-Disruptive Sorting.

Suppose I have a list of things (numbers, to keep things simple here) and I have a function I want to use to sort them by, using SortBy. For example, the following sorts a list of numbers by last digit: SortBy[{301, 201}, Mod[#,10]&] And notice how two of (ie, all of) those numbers have the same last digit. So it doesn't matter which ...

C#.NET :How to Sort a List <T> by a property in the object

I have a class called Order which has properties as OrderId,OrderDate,Quantity,Total. I have a List of this "Order" class. List<Order> objListOrder=new List<Order> (); objListOrder=GetOrderList(); // method to fill list of orders Now i want to sort the list based on one property of the Order object(Ex :i need to sort by the order dat...

How to speed up processing a huge text file?

I have an 800mb text file with 18,990,870 lines in it (each line is a record) that I need to pick out certain records, and if there is a match write them into a database. It is taking an age to work through them, so I wondered if there was a way to do it any quicker? My PHP is reading a line at a time as follows: $fp2 = fopen('do...

DataTable sort test question

I was asked this question recently in a test, which I didn't pass. For the life of me, I couldn't spot what the problem was. It's probably something really obvious as well, but even a colleague of mine couldn't spot it either. The best I could come up with was issues with bottlenecks and naming inconsistencies of parameters! I blame i...

What is the fastest way to sort 1 million integers when integers are from the range [1,100]?

Notes: I've thought about Radix sort, bucket sort, counting sort. Is there anyway to achieve big O(n)? ...

CouchDB sorting and filtering in the same view

Hi, I'm trying to use CouchDB for a new app, and I need to create a view that sorts by multiple fields and also filters by multiple fields. Here is an example document, I've left out the _id and _rev to save myself some typing. { "title": "My Document", "date": 1279816057, "ranking": 5, "category": "fun", "tags": [ ...

Dynamic grouping on element and attributes names

Hi! I would like to categorize results from an XPath under headings by element name (and then by same attribute names). Note: XML data could be inconsistent and some elements with the same name could have different attributes, therefore they need different headings. I can't seem to write out my problem in words, so it might be best to...

R - Sorting and Sub-setting Maximum Values within Columns

I am trying to iteratively sort data within columns to extract N maximum values. My data is set up with the first and second columns containing occupation titles and codes, and all of the rest of the columns containing comparative values (in this case location quotients that had to be previously calculated for each city) for those occu...

Sort a single linked list

How would you sort a single linked list. (the problem here is the single property + using LinkedList for sorting is harder than an array) I had like to see a pseudo code.. try to make it efficient as possible for both time and space. Thanks! ...

Search a sorted 2D matrix

M is a 2D matrix of integers (nXm) they are sorted in both row and column Write a function search(int s) that return the exact location of the number or Null. What would be the most efficient way to do so? ...

How to order (sort) a numeric value using simpleXML and PHP

I am extracting data from an XML Engine using simplexml, and I am completely stuck when I try to oder ASC or DESC the data. Be aware that I am not writing this values myself, but I am extracting them from another source. Ive got another response to a similiar question and I had this as an example (which works): $d = new SimpleXMLEle...

Sorting an array properly with php

I have an array that I wish to sort, it contains images with file extensions, the filename is numeric and the file extension is obviously a string. $files = array(); $files[] = '4.jpg'; $files[] = '14.jpg'; $files[] = '1.jpg'; $files[] = '44.jpg'; If i use sort() then I end up with the following: sort($files); print_r($files); Array...

Suppose I had a list in Python. What's the most pythonic and efficient way to randomize it by sections?

I have a list of X items. I want the first 10 to be randomized. Then, the 2nd 10 items to be randomized. Then the 3rd. What's the most efficient way to do this? ...

C++ array value sorting

If I want to sort the second dimension's 0 element like that: short arr[5]; arr[0][0] = 122; arr[0][1] = 33; arr[0][2] = 45; arr[1][0] = 33; arr[1][1] = 12; arr[1][2] = 42; . . . It will sort arr[i][0], but arr[i][1] and arr[i][2] will come with arr[i][0] to a new element. ...

How to sort files numerically from linux command line

Okay, now this is more a rant about Linux than a question, but maybe someone knows how to do what I want. I know this can be achieved using the sort command, but I want a better solution because getting that to work is about as easy as writing a C program to do the same thing. I have files, for arguments sake, lets say I have these file...

jqGrid with Custom sorttype

I am using jqGrid 3.7.2 with local data. For some columns the default sorttypes are not sufficient. I need to provide a custom sorttype, which I understand from the documentation is possible. I don't know how to get it to work though. The code below is my best attempt at getting it to work - I can't make it call the custom sorting functi...

Efficient ways to sort a deck of actual cards

I often have to sort decks of cards. These are "collector" cards numbered from 1 to 216 and there are doubles and missing numbers. I'm looking for sorting algorithms that work well with physical cards. Insertion sort seems fine because inserting a card does not require a shift of the subsequent cards like in a computer memory. However, ...

Python Sorting Question

Hi, i need to sort the following list of Tuples in Python: ListOfTuples = [('10', '2010 Jan 1;', 'Rapoport AM', 'Role of antiepileptic drugs as preventive agents for migraine', '20030417'), ('21', '2009 Nov;', 'Johannessen SI', 'Antiepilepticdrugs in epilepsy and other disorders--a population-based study of prescriptions', '19679449'),....

Sorting an array with instances of a custom class

Hi I have an array filled with instances of a custom class which contains two String properties, firstname and lastname. Both have a getter method which is equal to the name of the property itself. There is also a method for retrieving the Full name of a person called "getFullName". Consider the example below. CustomClass *person = [[...