sorting

Updating sort keys after delete

I have a table which has a field sort_id. In this field there are numbers from 1 to n, that define the order of the data sets. Now I want to delete some elements and afterwards I want to reorder the table. Therefore I need a query that "finds" the gaps and changes the sort_id field according to the modifications. Sure, I could do someth...

Sorting and Filtering Records

is there any known pattern/algorithm on how to perform sorting or filtering a list of records (from database) in the correct way? My current attempt involves usage of a form that provides some filtering and sorting options, and then append these criteria and sorting algorithm to my existing SQL. However, I find it can be easily abused th...

Sorting algorithm for a non-comparison based sort problem?

I am currently faced with a difficult sorting problem. I have a collection of events that need to be sorted against each other (a comparison sort) and against their relative position in the list. In the simplest terms I have list of events that each have a priority (integer), a duration (seconds), and an earliest occurrence time that th...

How do you sort all your old projects?

I was just looking through my system and have a lot of old projects that have multiple backups and versions (yes I know, it's before I started using source control properly ;) ) The thing is, some of these apps are used everyday by my company and many may have a lot of code that may be useful to other projects. So I am wanting to go th...

List ranking algorithm

Given a list of numbers, which can be in any order, such as 3, -5, -1, 2, 7, 12, -8 I would like to produce a list which represents their rank, which in this case would be 4, 1, 2, 3, 5, 6, 0 The numbers are actually some member of an ordered list of classes. Note that the order of the list does not change, they just get counted a...

Is there a more efficient way to do this SQL Select?

I have this SQL query: SELECT * FROM IMAGES WHERE IMAGENAME in ('IMG1', 'IMG2', 'IMG3', 'IMG4', 'IMG5', 'IMG6') ORDER BY CASE IMAGENAME WHEN 'IMG1' THEN 1 WHEN 'IMG2' THEN 2 WHEN 'IMG3' THEN 3 WHEN 'IMG4' THEN 4 WHEN 'IMG5' THEN 5 WHEN 'IMG6' THEN 6 ELSE 7 END I cannot guarantee that the list of IMAGENAMEs will be in alp...

JQuery tablesorter problem

Hi, I'm having a couple of problems with the JQuery tablesorter plugin. If you click on a column header, it should sort the data by this column, but there are a couple of problems: The rows are not properly sorted (1, 1, 2183, 236) The total row is included in the sort Regarding (2), I can't easily move the total row to a table foot...

What is the easiest way to order a <UL>/<OL> in jQuery?

I'm looking for some sample code that will sort the list items in an HTML list by alphabetical order. Can anyone help? Here is a sample list for people to work with: <ul class="alphaList"> <li>apples</li> <li>cats</li> <li>bears</li> </ul> ...

Is there an easy way to sort an array of char*'s ? C++

I've got an array of char*'s in a file. The co. I work for stores data in flat files.. Sometimes the data is sorted, but sometimes it's not. I'd like to sort the data in the files. Now I could write the code to do this, from scratch. Is there an easier way? Of course an inplace sort would be the best option. But I'll consider all o...

Sorting structures in order of least change

This came out being incomprehensible. I will rephrase Is there an algorithm or approach that will allow sorting an array in such a way that it minimizes the differences between successive elements? struct element { uint32 positions[8]; } These records are order-insensitive. The output file format is defined to be: byte present; ...

How do I divide an ordered list of integers into evenly sized sublists?

Does anyone have a good algorithm for taking an ordered list of integers, i.e.: [1, 3, 6, 7, 8, 10, 11, 13, 14, 17, 19, 23, 25, 27, 28] into a given number of evenly sized ordered sublists, i.e. for 4 it will be: [1, 3, 6] [7, 8, 10, 11] [13, 14, 17, 19] [23, 25, 27, 28] The requirement being that each of the sublists are ordered and a...

Sorting on the server or on the client?

Hello, I had a discussion with a colleague at work, it was about SQL queries and sorting. He has the opinion that you should let the server do any sorting before returning the rows to the client. I on the other hand thinks that the server is probably busy enough as it is, and it must be better for performance to let the client handle the...

How to write a compare function for qsort from stdlib?

I have a structure: struct pkt_ { double x; double y; double alfa; double r_kw; }; typedef struct pkt_ pkt; A table of these structures: pkt *tab_pkt; tab_pkt = malloc(ilosc_pkt * sizeof(pkt)); What I want to do is to sort tab_pkt by tab_pkt.alfa and tab_pkt.r: qsort(tab_pkt, ilosc_pkt, sizeof(pkt), porownaj); Where po...

How to use std::sort with a vector of structures and compare function?

Thanks for a solution in C, now I would like to achieve this in C++ using std::sort and vector: typedef struct { double x; double y; double alfa; } pkt; vector< pkt > wektor; filled up using push_back(); compare function: int porownaj(const void *p_a, const void *p_b) { pkt *pkt_a = (pkt *) p_a; pkt *pkt_b = (pkt *) p_b; ...

Safe To Modify std::pair<U, V>::first in vector of pairs?

I'm currently working on a DNA database class and I currently associate each row in the database with both a match score (based on edit distance) and the actual DNA sequence itself, is it safe to modify first this way within an iteration loop? typedef std::pair<int, DnaDatabaseRow> DnaPairT; typedef std::vector<DnaPairT> DnaDat...

Java Bit Operations (In Radix Sort)

The other day I decided to write an implementation of radix sort in Java. Radix sort is supposed to be O(k*N) but mine ended up being O(k^2*N) because of the process of breaking down each digit to one number. I broke down each digit by modding (%) the preceding digits out and dividing by ten to eliminate the succeeding digits. I asked my...

Is there an upside down caret character?

I have to maintain a large number of classic ASP pages, many of which have tabular data with no sort capabilities at all. Whatever order the original developer used in the database query is what you're stuck with. So I want to to tack on some basic sorting to a bunch of these pages, and I'm doing it all client side with javascript. I ...

How do I insert a DOM element in an ordered list (in Dojo)?

I'm trying to make an AJAXy submission and have the resulting partial be inserted into my list at the proper place. I can think of a few options, but none is terribly good: Option 1: Return JSON, do rendering in Javascript. That seems like the wrong place to render this, especially since the list itself is rendered in my application s...

Sorting XML nodes based on DateTime attribute C#, XPath

I have a XML Structure that looks like this. <sales> <item name="Games" sku="MIC28306200" iCat="28" sTime="11/26/2008 8:41:12 AM" price="1.00" desc="Item Name" /> <item name="Games" sku="MIC28307100" iCat="28" sTime="11/26/2008 8:42:12 AM" price="1.00" desc="Item Name" /> ... </sales> I am trying to find a ...

Sorting a List of Reviews Chronologically

I am trying to sort a list of movie reviews in chronological order. We have two options users can choose from, chronological and alphabetical. The page defaults to alphabetical, but when people click on the chronological option, nothing happens. Here is the code we have right now: // category 3 is 'reviews', category 12 is 'dvd reviews...