sorting

How to sort an array in php

i want the same value has the same index for example 1 2 2 3 5 after sort: array( 0=>1 1=>2 1=>2 3=>3 4=>5); but we can not set duplicate index in the array of php. ...

C++ STL: Custom sorting one vector based on contents of another

This is probably best stated as an example. I have two vectors/lists: People = {Anne, Bob, Charlie, Douglas} Ages = {23, 28, 25, 21} I want to sort the People based on their ages using something like sort(People.begin(), People.end(), CustomComparator), but I don't know how to write the CustomComparator to look at Ages rather than...

Sorting a 3 parallel list that includes strings and numeric value in Python

how to sort using 3 parallel array lists: num1 = ['a','b','c,'] num2 = ['apple','pear','grapes'] num3 = [2.5,4.0,.68] I used 2 for statements followed by a if statement. Sorting by elements the output should be: a apple 2.5 b pear 4.0 c grapes .68 unfortunately, I am having issues with sorting the 3rd n...

C++ Array Sort Me

Stuck on an array sorter. Have to sort numbers from largest to smallest. I'm trying two loops (one nested in the other). Here's the code: int counter=0; // inner counter int counter2=0; // outer counter int sparky[14]; //array set to 14 just to simplify things int holder; // holds the highest value int high; //stores the position where ...

What is the most efficient way to create a distinct list of items using .NET?

I have a large list of values (100-200 character strings) and I need to return a distinct listing of them. What is the most efficient way to do this using .NET? The 2 ways that I can think of are: Use the Distinct() method of the IEnumerable class Use a Dictionary If the Dictionary approach is faster in raw terms, consider a trade-...

Linq operations against a List of Hashtables?

I'm working with a set of legacy DAO code that returns an IList, where each Hashtable represents the row of a dynamically executed SQL query. For example, the List might contain the following records/hashtables: Hashtable1: Key:Column15, Value:"Jack" Key:Column16, Value:"Stevens" Key:Column18, Value:"7/23/1973" Key:Column25, Value:"Act...

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID's and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array - sortArray. Then when i diplay the results i plan on using the data from sort array to find out what color the voteArray data should have...

Grid sorting with persistent master sort

I have a UI with a grid. Each record in the grid is sorted by a "master" sort column, let's call it a page number. Each record is a story in a magazine. I want the user to be able to drag and drop a record to a new position in the grid and automatically update the page number field to reflect the updated position. Easy enough, right?...

Using a non-static class member inside a comparison function

Hello everyone, I'm currently developing a syntaxic analyser class that needs, at a point of the code, to sort structs holding info about operators. Each operator has a priority, which is user-defined through public member functions of my analyser class. Thus, when sorting, I need my sorting function to order elements based on the prior...

Grokking Timsort

There's a (relatively) new sort on the block called Timsort. It's been used as Python's list.sort, and is now going to be the new Array.sort in Java 7). There's some documentation and a tiny Wikipedia article describing the high-level properties of the sort and some low-level performance evaluations, but I was curious if anybody can pro...

Where can I get C/C++ sample code for merge sort a link list?

Where can I get a sample code for merge sort a link list? ...

What is the best way to sort link list?

What is the best algorithm to sort a link list [in C/C++]? ...

How do I sort enum members alphabetically in Java?

I have an enum class like the following: public enum Letter { OMEGA_LETTER("Omega"), GAMMA_LETTER("Gamma"), BETA_LETTER("Beta"), ALPHA_LETTER("Alpha"), private final String description; Letter() { description = toString(); } Letter(String description) { this.description = description; ...

referencing java objects on a sorted map by index?

I have a sorted map and want to reference its ordered objects by their index position. Is this possible? How would I convert a sorted map to an array list while maintaining the ordering, so I can retrieve an object by its index (order). Is this the only way to do it? Ideally I could have this structure, and would know the index of an ob...

Merge Sort Java

Hi. I am trying to make a merge sort method, but it keeps on giving the wrong sorts. Where do I have change to make it actually sort the array? What part of the code has to be different? Thank you for your time. public static void mergeSort(int[] array, int left, int lHigh, int right, int rHigh) { int elements = (rHigh - l...

looking for ideas on how to force order of pictures in a gallery (django app)

Hi - I'm building a django app that has an image gallery, and the client insists the images be displayed in specific order. I use the admin interface to upload the images and edit their properties, and I have an ImageFile class in my model that basically looks like this: class ImageFile(models.Model): """represents an image file""" ...

sorting function in python.

Hi, I'm trying to sort a list of objects according to my criteria. Here is my sorting function: def sort_pots(self, pot1, pot2): coeff1 = ((pot1.movable + pot1.convertible) / pot1.total) coeff2 = ((pot2.movable + pot2.convertible) / pot2.total) if coeff1 > coeff2: return 1 elif coeff1 == coeff2: retur...

achieving a complex sort via Linq to Objects

I've been asked to apply conditional sorting to a data set and I'm trying to figure out how to achieve this via LINQ. In this particular domain, purchase orders can be marked as primary or secondary. The exact mechanism used to determine primary/secondary status is rather complex and not germane to the problem at hand. Consider the d...

How to sort model by values in a dictionary?

In Django, I have a model, and I will have a dictionary having the id's of objects in this model as keys, and a weight as values. I would like to use these weights in an order_by: MyModel.objects.filter(title__icontains=query).order_by( 'value_from_the_dictionary' ) How to make this work? I can't put the weights in the model, as they...

How Can I Sort an ADO Table on a Fieldname Containing a Space?

I am using Delphi, but this is a simple and general problem: I'm doing the following: var ArticlesTable: TADOTable; begin ArticlesTable.DisableControls; ArticlesTable.Sort := 'CITY'; ArticlesTable.First; while not ArticlesTable.Eof do begin ... ArticlesTable.Next; end; This works very well and allows me to effici...