sorting

Rails sorting child objects and displaying

Relating to my last question here: http://stackoverflow.com/questions/3740724/rails-finding-all-associated-objects-to-a-parent-object Is it possible to sort multiple separate child objects in Rails by creation date, and then list them? Using the previous example I have a resume with two different has_many child objects, I would like to ...

Magento category sorting by attributes

Hello all, I am currently trying to make a special sort function for a Magento category page. I have several attributes, which I need to use for sorting: The first attribute is named designers. This attribute is set on a configurable product. The next attributes are named colour and size. These are not set on the configurable product...

php sort array with preference

Hi, I have array and contains 50 values , example london,bluehit,green,lonpark,abc,aab,lonsee i want to sort as per my preference , i give one argument , example if i give arugment as lon then my array should form like london,lonpark,lonsee,aab,abc,blurhit,green,lonsee , so in the above my array output is i gave parameter as lon ...

Entity Framework 4 - Sorting by foreign entity

I get "'System.Windows.Data.BindingListCollectionView' view does not support sorting." when I use the following CollectionViewSource: <CollectionViewSource Source="{Binding Path=CourseSessions}" x:Key="cvsCourses"> <CollectionViewSource.SortDescriptions> <ComponentModel:SortDescription PropertyName="StartDate"/> ...

How would I do Subsequent sort on a child table in asp.net mvc2 using Entity Framework

I am trying to do something like this: ViewData.Model = _db.Questions .Include("QType") .Include("QTags") .Include("SubQuestions.Options") .Where(q => q.Active == true) .Orderby(q => Questions.Order) ...

How to order an array of objects by a certain property in XCode

Let's say I have an array of custom objects. The custom class looks like this Person ------- name number Now let's say I want to rearrange the array of these objects so that the objects are sorted by the number. How can this be done? ...

Sorting in arrays

While sorting an array for ex: A[5]={1,4,5,3,2} the output must be 1,2,3,4,5 in ascending order. in using the concept of bubble sorting my output is 0,1,2,3,4 what would be the problem in my code int A[5]={1,5,3,2,4}; for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ if(A[j]>A[j+1]) { int t=A[j]; A[j]=A[j+1]...

Need a way to sort a 100 GB log file by date.

So, for some strange reason I end up with a 100GB log file that is unsorted (actually it's partially sorted), while the algorithms that I'm attempting to apply require sorted data. A line in the log file looks like so data <date> data data more data I have access to C# 4.0 and about 4 GB of RAM on my workstation. I would imagine that ...

Changing semantics of subclass methods in java

I've recently learned like 3 new languages and I'm starting to get them confused. I haven't worked Java in doing anything particularly complex (outside of android) in a couple years. I'm having trouble remembering if this is possible: I'm subclassing ArrayList mainly so I can keep the arraylist ordered. I'm trying to override the add(ob...

Capitalize first letter in PHP using RegEx?

I have data in a notepad file as following: A 1-6 A 1-7 B 1-8 B 1-9 B 1-10 c 1-11 C 1-12 D 1-13 F 1-14 F 1-15 f 1-16 I want above data to be updated as below in the notepad file: <strong>A</strong> 1-6 A 1-7 <strong>B</strong> 1-8 B 1-9 B 1-10 <strong>c</strong> 1-11 C 1-12 <strong>D</strong> 1-13 <s...

Help with T-sql special sorting rules

I have a field like: SELECT * FROM ( SELECT 'A9t' AS sortField UNION ALL SELECT 'A10t' UNION ALL SELECT 'A11t' UNION ALL SELECT 'AB9F' UNION ALL SELECT 'AB10t' UNION ALL SELECT 'AB11t' ) t ORDER BY sortField and the result is: sortField --------- A10t A11t A9t AB10t AB11t AB9F Actually I need ...

Sorting Mulitdemensional Array PHP

I have the following array, it is currently created sorted by entity_count (outputted by a query done in cakephp - I only wanted the top few entities), I want to now sort the array for the Entity->title. I tried doing this with array_multisort but failed. Is this possible? Array ( [0] => Array ( [Entity] => Arra...

Sorting with collections in java

Hello EveryOne, I have a tricky question in sorting with collection. I have a HashMap which contains some thing like the following HashMap<String,QuoteBean> mapToSort=new HashMap<<String,QuoteBean>(); QuoteBean is basically a java bean which has properties with setter and getter methods Which looks like the following. //class QuoteB...

jqGrid sort icon displayed when no sorting performed

In our grid we do not have sortName or sortOrder defined but the first column has the sort icon displayed (in ASC order). How can you prevent the sort icon from appearing? Update: Code below $("#list").jqGrid({ url:'NoData.json', datatype: 'json', mtype: 'GET', colNames:['Product', 'Type','Expiry', 'Put Call', 'Str...

Java Mapping ArrayList to HashMap

Hi there I have page gets given an ArrayList<Document> where each document has a property called type. I don't know the number of unique types or documents. I want to sort this ArrayList into a HashMap<type, document[]> but am having some trouble getting my head around it. Some pseudo-code would like like for (int i = 0; i < documen...

Different sort algorithms visually performed

Any decent visualization of a couple different sort algorithms? I'm looking for something I can use in a demo, and willing to write my own (can't be that hard) but would prefer to use someone else's if I can. NO applets though, the majority I'm finding are applets... Lightweight flash or canvas. I would like the following sorts: Bubbl...

Custom Sorting with usort in PHP - Numerical sort with 0 at the end of the list

Hi For the last couple of days i tried to get my head around the following: I have a 2-dimensional Array and i try to sort it with a custom algorithm using usort(). My Problem is, that I'm trying to sort numbers like in the order of 1 2 3 0 so the zero should always be the last item. function customsort($e1, $e2) { if ($e1["numbe...

C# faster sorting than SortedList<>

Hi we have a SortedList<Resource, Resource> resources = new SortedList<Resource, Resource>(new ResourceIdle()); that we use in our simulation. This list of resources is initialised in this way because we want to pass different comparers at any point in time. First problem we have is that the SortedList<> requires an extra compar...

Radix Sort in JavaScript

I've come up with the following but it predictably doesn't work. var t = new Array(a.length); var r = 4; var b = 64; var count = new Array(1<<r); var pref = new Array(1<<r); var groups = Math.ceil(b / r); var mask = (1 << r) - 1; var shift = 0; for(var c = 0; c < groups; c++) { shift += r; for(var j = 0; j < count.length; j...

Javascript in IE8: how to sort array of objects by alphanumeric property

I've got an array of Javascript objects that I'd like to cross-compatibly sort by a property that is always a positive integer with an optional single letter at the end. I'm looking for a solution that works in at least Firefox 3 and Internet Explorer 8. The closest I've come to such a sort function is the following: var arrayOfObjec...