sorting

Sort an array of char in C

I have been struggling to write a simple code to sort an array of char in C and been failing miserably. This is what I have so far: int main() { char line[128]; char word[128]; int i=0; int j; int length; while(fgets(line,sizeof line,stdin) != NULL) { length=0; i=0; while (line[i]!='\0') i++; lengt...

Algorithm Interview Question

Hi all: I went to an interview today and here is the question: Suppose you have got 1 billion integers which are unsorted at one disk file,please find out the largest 100 numbers,try the best solution as you can. Anybody who has ideas,please do share! Thanks in advance! ...

Algorithm to determine most popular article last week, month and year?

I'm working on a project where I need to sort a list of user-submitted articles by their popularity (last week, last month and last year). I've been mulling on this for a while, but I'm not a great statitician so I figured I could maybe get some input here. Here are the variables available: Time [date] the article was originally publ...

Getting the average order out of multiple lists

Assuming that I have multiple ordered lists like this: list_1 = ["apples", "oranges", "bananas"] list_2 = ["apples", "pineapple", "grapes"] list_3 = ["melons", "pineapples", "apples"] How would I calculate the average order? I could loop over all items and get the average position for all lists. However what would I do when an item is...

In Java, How do you quicksort an ArrayList of objects in which the sorting field is multiple layers deep?

Basically, I have a Container class called "Employees" which has in it an ArrayList. This ArrayList contains "Employee" objects, which in turn contain "EmployeeData" objects which in turn contain String objects such as "first" or "last" (which are employee names). Here's a diagram of the ArrayList structure: ArrayList[Employee] emps ==...

Comparison Based Ranking Algorithm

I would like to rank or sort a collection of items (with size potentially greater than 100,000) where each item in the collection does not have an intrinsic (comparable) value, instead all I have is the comparisons between any two items which have been provided by users in a 'subjective' manner. Example: Consider a collection with el...

How CompareTo method logic works in List sort function?

How CompareTo method logic works in List sort function. public class person : IComparable { string firstName; string lastName; public int CompareTo(object obj) { person otherPerson = (person)obj; if (this.lastName != otherPerson.lastName) return this.lastName.CompareTo(otherPerson.lastName); ...

Sort one C# list by another

I have 2 list objects, one is just a list of ints, the other is a list of objects but the objects has an ID property. What i want to do is sort the list of objects by its ID in the same sort order as the list of ints. Ive been playing around for a while now trying to get it working, so far no joy, Here is what i have so far... ...

Multi-sort Media Wiki Tables

Hello, I am trying to allow sorting a wiki table that use the "sortable" class by multiple columns. Eg: {| class="wikitable sortable" |- |Col 1 |Col 2 |Col 3 |- |3 |a |tee |- |2 |c |hot |- |5 |b |apple |} That will give you a basic sortable table on the wiki, but it won't let you sort by multiple co...

How to access bound resource after sorting gridview WPF

Hi I am binding an observable collection to my gridview. public ObservableCollection<LibraryTrack> Biblio { get { return _Biblio; } } The gridview only contains the necessary values for the user to see. The secondary information like filelocation and file id isn't bound to the gridview, this info is in this case useless for ...

Generating a Recency Rating

I have a data table that is periodically updated by another service. I log when these updates occur in the database. I'd like to be able to somehow rate the most recently updated data records. I don't want to select exactly the most recent, I'd like to sort of account for previous updates as well. I'll try and explain what I mean usi...

How to create a Generic Bubble Sorting in c#

I am currently working on making my own Generic Bubble Sorting which can easily sort Strings, int. Below is my Code for Normal Bubble Sorting.Can you help me out how to create a generic Method Of this? public static void BubbleSorting() { int Swap; for (int outer = Length; outer >= 1; outer--) { for (...

How to sort a table using javascript?

I have an HTML table with about 100 rows and 3 columns. I have onclick events attached to all 3 of my column headers. What must I do in Javascript to easily sort the table by that column? I can think of a fully blown hand-written approach, but I'm not sure if there are any built-in functions for such a seemingly common operation. If I h...

PHP - sort hash array by key length

I've found a few answers to sorting by value, but not key. What I'd like to do is a reverse sort, so with: $nametocode['reallylongname']='12'; $nametocode['shortname']='10'; $nametocode['mediumname']='11'; I'd like them to be in this order reallylongname mediumname shortname mediumname shortname Many thanks ...

Sort a large collection while showing progress

What is the best way to sort a collection while updating a progress bar? Currently I have code like this: for (int i = 0; i < items.size(); i++) { progressBar.setValue(i); // Uses Collections.binarySearch: CollectionUtils.insertInOrder(sortedItems, item.get(i)); } This shows progress but the progress bar slows down as the...

Sorting algorithm for large datasets

Hi, I don't know whether the term sort is most appropriate but anyway I have a large datasets which consists of columns userA, userB, date, interactionDuration. In other words the dataset contains rows which describe which users were interacting, how long the interaction lasted and the date of interaction. The goal is to divide these i...

jQuery Sorting and Filtering Multiple Columns

I want to be able to sort and filter multiple columns using a jquery plugin. Does anyone know of any that will do this? The following example is very close to what i want except it doesn't do multiple sorts http://mleibman.github.com/SlickGrid/examples/example4-model.html Thanks! ...

How to sort ENUM column in MySQL database ?

I have color column in MySQL table which type is ENUM('RED', 'YELLOW', 'MY_COLOR', 'BLACK'), and another name column which type is VARCHAR(30). I would like to get all table rows in the following order: YELLOW rows first, sorted by name RED rows last, sorted by name In the middle, all other rows, sorted by name Is that possible to m...

Sort Divs every X amount of seconds with JQUERY

I have 5 divs, each having count down timers. The following numbers would obviously be be divided by <br/>'s , but for the sake of the example I am trying to be as clear as possible :-) Example before sort 4.39 3.45 2.11 3.56 1.11 Example after sort 4.39 3.56 3.45 2.11 1.11 And each countdown counts to 0 obviously. I had in mind, ...

Fastest way of sorting this multidimensional array?

What is the fastest way of sorting this both alphabetically by country and numerically by date?: Array ( [JAPAN] => Array ( [2010-10-17] => 2 ) [CUBA] => Array ( [2010-10-16] => 9 ) [RUSSIAN FEDERATION] => Array ( [2010-10-16] => 26 [2010-10-17] => 6 [2010-10-18] => 2 ) ...