Click here to Skip to main content
15,886,110 members
Everything / General Programming / Sorting

Sorting

sorting

Great Reads

by Christoph Buenger
Describes PHP application development with the free Scavix Web Development Framework (Scavix-WDF).
by Member 9294701
A simple, portable yet efficient Quicksort implementation in C
by brunofer2007
Easy way to sort nodes in a TreeView using a recursive function.
by DotNetLead.com
How to implement paging and sorting to yield good performance

Latest Articles

by Perić Željko
Sorting Multi-Dimensional Arrays in C# with QuickSort Sort Extensions
by Ramesh Bevara
An overview of a helper class to build dynamic order by clause in LINQ query in C#
by spore123
This is a fast multi-threaded quick-sort based algorithm
by The Sun God
Comparison of the various sorting algorithms on the basis of several factors

All Articles

Sort by Updated

Sorting 

17 Feb 2010 by #realJSOP
Try this:emails = (from p in DatabaseConnection.Emails where p.Newsmail == true select p).Distinct();
22 Apr 2010 by #realJSOP
With the pitiful amount of info you've provided, the best I can suggest is that you look into using a Dictionary object instead of an Array.
16 Mar 2011 by #realJSOP
Don't use an ArrayList - use a generic collection. Once you've converted your code, check out this tip/trick:A Generic Comparison Class for Collection Items[^]
15 Jul 2011 by #realJSOP
If all of your data will fit in available memory, you could retrieve all of the data you need to display, and then extract only the items that will fit in a page. Psuedo code:0) retrieve data 1) Calculate number of pages you have - Math.Min(1, Math.Floor(records_retrieved /...
21 Jun 2011 by 2irfanshaikh
I think this will help youhttp://stackoverflow.com/questions/1296532/making-a-datagrid-column-header-sortable-in-wpf-using-c[^]Or else try to put it into the SortMemberPath header template
15 Sep 2020 by 5atyam5rivastava
The following code block runs for only 1 iteration. Giving the output : [1,9,8,7,6,5,4,3,2,10] Kindly help in resolving the logical bug. What I have tried: ''' Program to implement Selection Sort The time complexity of above algorithm is O(n^2)...
24 Jul 2012 by _Amy
Hi,Use this://Dropdownlist selected value changed event. This can be done on button click event also.protected void DropDownList1_SelectIndexChanged(object sender, EventArgs e) { gvSorting.Sort(DropDownList1.SelectedValue, SortDirection.Ascending); ...
1 Oct 2012 by Aarti Meswania
convert loan_number in to numeric if it will not contain alphabet ever.fetch data from sql like below,select convert(numeric,'999') -- replace underline with Loan_Number in your query now, field is numeric so it will apply sorting properly.Happy Coding!:)
19 Dec 2012 by Aarti Meswania
Note: Numeric conversion is must in this case for sorting AND insert data in proper formatsee below example...select dbo.SetFormat(duration) from( Select '33:14:14' as 'Duration' UNION Select '01:16:36' as 'Duration' UNION Select '0:3' as 'Duration' UNION ...
15 Feb 2012 by Abbas_here
Abbas_here - 2 mins agofrds, The problem is that client saying me to create a web service method which able to consume their SOAP file and return back authenticate result in response SOAP massage, Request SOAP:
9 Nov 2010 by AbbasKapasi
Hi,We have created a SSRS report over the analysis services database.This report is added to a web part in sharepoint 2010. When we sets the toolbar to be visible, sorting works fine but when it is made invisible, the request is not going to the report server and it shows report server...
14 Apr 2011 by Abhinav S
You might want to visit the RadGrid forums. This code looks fine to me.
28 Nov 2011 by Abhinav S
http://geekswi...
2 Apr 2012 by Abhinav S
To customize sort in a datagridview, go through this article - How to: Customize Sorting in the Windows Forms DataGridView Control[^].
26 Jul 2015 by Abhishrek
Hello all,I need to find N largest area contours available in a binary image.I wanted to try the OrderBy() function to sort the contours by Area.However, I am unable to understand the the syntax for keySelector used as a parameter in OrderBy() Although I am using EmguCV, but a C++...
18 Feb 2023 by Addy__0
#include #include #include char **StringArray(char **arr, int size); int main() { char **Str; int n= 5; int i; Str= (char**)calloc(5,sizeof(char)); Str[0]= (char*) calloc(10, sizeof(char)); ...
9 Dec 2021 by Admin BTA
I would like an efficient and non-invasive way of finding a median of a large array (a double array of size 300,000). What I have tried: I have tried an inefficient method: double Median(double[] xs) { Array.Sort(xs); return xs[xs.Length...
21 May 2012 by Aescleal
Repeat after me..."When I do a search in C++ and I don't use std::sort and std::find I shall go and punch myself in the head OR, preferably as I don't like pain, I shall rewrite my class so it can be put in a collection and sorted and searched."Having said that, how can you write a class...
21 Jun 2011 by afva
Hello , In my datagrid my textColumn looks like:Collapse IsReadOnly="True" Width="300" Binding="{Binding Path=CT_APPR.NAME}" SortMemberPath="{Binding Path=CT_APPR.NAME}" >My datagrid looks fine, so the binding is correct.But when I click on the...
9 Mar 2014 by agent_kruger
How to sort multiple time and on specific text in c# win. form like i have records in DataTable like thisRecordId Name 1 5% VAT 2 12.5% CST 3 12.5% VAT 4 14% VAT 5 2% CSTAnd want Desired Result like thisId Name 1 5% VAT 2 12.5% VAT 3 14% VAT 4 2% CST...
14 Mar 2019 by agent_kruger
I am stuck at the part of Sorting a group of integers according to their length and Un-Sorting it back.ExampleBelow is my integer array that i want to get serializedint[] i = new int[] { 20,5,90,7,44,81 };OUTPUTi = new int[] { 5,7,20,90,44,81 };UNSORTINGi = new int[] {...
12 Sep 2023 by Ahmed Abdelsalam 2023
#include #include #include struct triangle { int a; int b; int c; }; typedef struct triangle triangle; void sort_by_area(triangle* tr, int n) { int i,j; double p; int *S = malloc(n * sizeof(int)); ...
23 Sep 2012 by Ajay J Singh
" SelectCommand="SELECT * FROM [AppSetting] ORDER BY [SettingID]">
20 Dec 2010 by Albin Abel
Simple Pattern Matching Technique for Search Suggest Boxes
16 Feb 2011 by Albin Abel
Hi,There are many ways to achieve this.1) The best way would be using a clustering algorithm with a maximum likelihood function. On the result of it each pixel will have a cluster membership. So in your subsequent search's you only need to search within the cluster members, not all the...
6 Jun 2011 by alessandro.campagna
Hello, I have a DataGridView associated to a bindingSource:bindingSource1.DataSource = dataset1;bindingSource1.DataMember = "table1";dataNavigator1.DataSource = bindingSource1;dataGridView1.DataSource = bindingSource1;And I have two functions to move up and down a selected...
6 Jun 2011 by alessandro.campagna
I made some progress but still there're some problems after sort by clicking on header grid collumn. I tried to reset the bindingSource1.Sort = ""; in the move rows function, and the row and now the row get moved but the position is wrong!! Here the code so you try by yourself.. public...
18 Jul 2014 by Alexander Batishchev
How to create a sorting expression from GridViewSortEventArgs using LINQ Expression Tree.
28 Mar 2015 by Alexis i
could anyone please tell me how this code sorts the array? i don't get it! and how is this code reducing the complexity of a regular insertion sort?// Function to sort an array a[] of size 'n'void insertionSort(int a[], int n){ int i, loc, j, k, selected; for (i = 1; i
15 Nov 2013 by Ali_100
http://postimg.org/image/8fm4y...
24 May 2014 by AlwaysLearningNewStuff
I have successfully populated linked list with data from a text file. Linked list contains structure that has 5 fields of type string.I wish to sort the list by a certain structure field ( ascending or descending ). I have decided to overload operator
3 Mar 2014 by Amalraj Ramesh
Try this DataView dataview = ft.DefaultView; dataview.Sort = "ColumName"; DataTable dt = dataview .ToTable();
18 Dec 2012 by Amir Mahfoozi
Hi,One solution is converting your data to seconds either on the fly or by using a user defined function.Here is a SQL statement that converts your data to seconds on the fly :SELECT * FROM (SELECT Duration ,CASEWHEN CHARINDEX(':',Duration )=0 THEN CAST (Duration AS...
6 Mar 2014 by Amogh Natu
Hi,I have implemented a repeater control which has some columns and data. For each column header, in the header template, I have defined a label for the header text and an tag for showing the direction of sorting (asc or desc). Sample code below:
28 Dec 2014 by Amresh Bahadur Singh
you can use LINQ for itAnd check this url.http://stackoverflow.com/questions/5295971/sorting-a-list-with-orderby[^]
5 Dec 2012 by amrita_thakur
Hi...I have a WPF Datagrid which I've grouped by a column ProductName. I want to perform sorting on UploadDate which is a datefield. The issue here is on clicking on sort I want the data to be sorted on UploadDate within the groups, by the datagrid sorts the data based on the ProductName, on...
2 Jul 2017 by an0ther1
I cannot see where you are actually applying the sort. If your event handler grdCustomers_Sorting is not firing then check the GridView has the property AllowSorting=True If your event handler is firing then it is likely to be because you have not applied the sort from e.SortExpression. Review...
26 Jul 2014 by Andreas Gieriet
If it's about having various collating sequences, you might use the approach as described in Sorting C# collections that have no collating sequence[^].CheersAndi
28 Nov 2015 by Andreas Gieriet
Never ever reinvent sorting yourself. If this is a homework assignment, do it according to your text book. If it is otherwise needed, use any existing sorting, i.e. by using some of the existing Sort functions, e.g.Array.Sort(complexArray,(a,b)=>a.real.CompareTo(b.real));RegardsAndi
16 Mar 2011 by Andrew Rissing
How to sort a two-dimensional array in C#
18 Jan 2013 by Andrey Sitaev
Here I placed source files, binaries and brief instructions for FastGrid control.
9 Sep 2017 by Andy Allinger
You need to be very careful in writing the for statement. If you use the
30 Jul 2013 by Antariksh Verma
Hi,I want to implement Grid using KendoUI in MVC 3.0 But the sorting and filtering does not work.the code of .cshtml file is :@(Html.Kendo().Grid(Model) .Name("Grid") .Sortable(sort => sort.SortMode(GridSortMode.MultipleColumn)) .Columns(columns => { ...
8 Aug 2013 by Antariksh Verma
Hi ,After doing lot of R&D in Kendo UI i got that if we want sorting ,filtering and paging on client side we have to add .ServerOperation(false) so that all functionality like Sorting and filtering works on client side.
14 Aug 2013 by Antariksh Verma
Hi ,After doing lot of R&D in Kendo UI i got that if we want sorting ,filtering and paging on client side we have to add .ServerOperation(false) so that all functionality like Sorting and filtering works on client side.
26 Jul 2015 by Artem Kulikov
Hello. You should notice, that in your code - you will get only one contour.For your purpose you should fistly get all contours, and after that order them. Check this code:var allContours = new List>(); for (var contours = image.FindContours(); contours !=...
11 May 2023 by ashan prabath
Problem You are given two non-decreasing sequences A = (A₁, A2,..., AM) and B = (B₁, B2,..., BN). You can choose any two indices i and j, and then swap A[i]; and B[j]. Note that the you can do the operations as many times as you want, and your...
6 Dec 2009 by Ashish Sheth
No need to count the commas.Use Textbox1.Text.Split(',').Length. It gives you the count of the numbers added in the textbox separated by comma.
11 Oct 2013 by ASP.NET Community
Both the GridView and ListView are important Data Controls in Visual Studio 2008.Scott Guthrie has a great introduction that uses the ListView
11 Oct 2013 by ASP.NET Community
The ListView is a sort of hybrid between a DataGrid and Repeater thatcombines the free form templating of the Repeater with the editingfeatures
7 Dec 2009 by AspDotNetDev
VB does not use a double equal sign to test for equality. It only uses a single equal sign. Try:e.Handled = (e.KeyChar = " ")Also, it doesn't use semicolons to end lines.
7 Dec 2009 by AspDotNetDev
This seems like a homework question...What do you need help with specifically? Sorting algorithms are well documented online. Have you searched online yet? Wikipedia has some good information. Once you've done that, then come here with specific questions and we'll be happy to assist (so long...
9 Dec 2009 by AspDotNetDev
Sounds like you want us to make your regular expression for you. What particular trouble are you having creating your regular expression?
29 May 2010 by AspDotNetDev
Excellent question. I believe I have an answer for you.Sort the pixels into 3 lists. Each list would be sorted by the color intensity of a color component (red, green, or blue). Now, make a grid and set each point to store information about where in the 3 arrays that pixel is located. The...
29 May 2010 by AspDotNetDev
Just to add to my previous answer, I thought of another optimization. In each of the 3 lists, you could store sublists. Say you have 10 pixels that have a red value of 0. Then redList[0] would contain a list of those pixels sorted accorded to their green values. So, redList[0][1] would store a...
30 May 2010 by AspDotNetDev
One more thing to optimize my previous suggestion. If you travel 1 color value at a time in all 3 lists at once, then you can keep track of how far you've travelled in the other lists to know what the best possible minimum color you could achieve is. That way, you can use that as an exit...
3 Apr 2019 by AtulSharma609
I got a response on a url Once I read the response i get this string as below ...
10 Dec 2013 by Aurélien BOUDOUX
A list for managing tens of millions of objects in your application.
25 Jul 2012 by ayerunka
Can anyone help me to convert the following Excel VBA code to C# - this is sorting on cell colour in excel :- There is a table in an excel file with columns as TowerName, Incident, Problem and Change. The column Incident contains values as cell colour in Red, yellow and Green. I need to sort...
21 Dec 2020 by Azbilegt Chuluunbat
The challenge is not how to implement it. I know how. Instead, the question is what sorting algorithm needs to be used to get the fastest sorting performance especially when the number of words increase in the sentence. Quick sorting is believed...
16 Dec 2012 by Basil_2
How to choose an STL sorting algorithm.
19 Sep 2013 by bedathur_ganesh
Hi,Sorting is not happening on the click of column headers. The "Loading..." shows up briefly over the data, but the columns are not getting sorted. Also, "OnSortCol" event gets triggered and I could see the alert popping up. But, the sorting is not happening. Any help on this is...
23 Feb 2017 by BeginnerCoderPete
I have a table in SQL that contains clock times gathered from the one clock-in point. The times appear in the table like so:pkClockingTime dtDateTime fkEmployee1 2017-02-06, 07:59:00.000 492 2017-02-06, 08:00:00.000 503 2017-02-06,...
31 Mar 2016 by Bhavika Mdm
I have an sql table, in which I need to select the data, that is sorted based on a value. For example,If the sort value is 1, then I need to sort by column1, column2 and then column3.If the sort value is 2, then I need to sort by column2, column1 and then column3.If the sort value is...
9 Feb 2015 by Bhis
Various ways to sort list and compare results
3 Mar 2014 by BillWoodruff
Yes, you can sort the values in an Enum for display in a ComboBox alpha-numerically, or any other way you want:// requires Linq// preserve the current ComboBox selectionprivate V currentVName;private void Form1_Load(object sender, EventArgs e){ var vAry =...
23 Mar 2014 by BillWoodruff
After playing with the CheckedListBox a while, I am convinced you will find it much easier to implement this using two ListBoxes. The ListBox offers you built-in sorting by setting its 'Sorted Property to 'true.If you still really wish to use a CheckedListBox, hopefully this code will give...
9 Dec 2021 by BillWoodruff
You could use the 'Median method in the open-source Math.NET Numerics library: [^]. For an interesting idea for an O(n) algorithm: [^] ... note: i have not used it.
2 May 2015 by bobb024
Hello,I have the example code behind below protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { } private string ConvertSortDirectionToSql(SortDirection sortDirection) { string newSortDirection = String.Empty; if...
23 Feb 2021 by Bojjaiah
I am trying to sorting the string field from the List, But not working for me. Both results are returning the same. var objNotSort = getLiveData(); var objWithSort = SoryByOperation(getLiveData()).ToArray(); I cannot changes this field to...
12 May 2014 by Brad Joss
[RegSave] your property to the Registry, and more.
26 Dec 2013 by Brien Givens
A performance improvement for the classic sort / select algorithms.
11 Sep 2011 by brunofer2007
Easy way to sort nodes in a TreeView using a recursive function.
19 Jan 2018 by Bryian Tan
This might be helpful - Native PHP Sort array of objects by property – Tormix Blog – Web development[^]
7 Apr 2019 by calvinsdad
Hi, I need to build an algorithm that can look at X number of records which have overlapping dates in them and organize and re-insert those date values in a chronological sequence. E.g.: The table has a record like this: Start Date End Date Value 1/1/2019 12/31/2099 10 When a new record like...
29 Oct 2014 by chandra sekhar
I am sorting a list based on priority value and it is integer lstRecData = lstRecData.OrderBy(x => x.strRecPriority).Reverse().ToList();But the ouput is not changed it is showing 4,3,2 instead 2,3,4
26 Mar 2013 by Chaoscommander
Hi,I have a DataGrid and bound an ObservableCollection to it:ObservableCollection MyValueList = new ObservableCollection();public MainWindow(){ gridViewReceivedValues.ItemsSource = MyValueList;}If I doMyValueList.Add(SomeValue);the...
13 Nov 2013 by Chetan Patel
Add this eventprivate void GridViewSortDirection(GridView g, GridViewSortEventArgs e, out SortDirection d, out string f){ f = e.SortExpression; d = e.SortDirection; //Check if GridView control has required Attributes if (g.Attributes["CurrentSortField"] != null &&...
25 Mar 2014 by CHill60
As Richard MacCutchan said, you will need to design a Database first to capture the information about each meal each user has had.Here's a link to a beginners guide to databases[^]Think carefully about the tables you will need and what sort of information you will need to...
11 Apr 2014 by CHill60
For sorting the list on value rather than key just provide an appropriate compare method ... have a look at this example http://www.dotnetperls.com/sort-keyvaluepair[^]If you want to treat the first 5 items differently to the rest then you could split the list into two separate ones before...
18 Feb 2015 by CHill60
An alternative approach (I'm not suggesting it's the best one!)You could have a Dictionary of , string>. For example, using your data which I've deliberately changed the order on, and just using string for the object for now var original = new...
14 Aug 2017 by CHill60
You appear to have at least 6 tables with exactly the same schema. This is usually a sure sign that your database design needs some attention. From what I can see all of this information could be (and should be) stored in a single table. Add another column that indications the "BuildingType" -...
11 Feb 2010 by Christian Graus
What a bizarre post. Blocked where ? By your work ? Are you a programmer ? If there was such a thing as code you could run on the local level that circumvented a block that exists on your firewall, would you know what to do with it ?
30 Aug 2010 by Christian Graus
You use an order by clause to specific the order of your data. It seems to be ordering by group by default, so you need to be able to specify the order by some value.
31 Oct 2014 by Christoph Buenger
Describes PHP application development with the free Scavix Web Development Framework (Scavix-WDF).
27 Nov 2013 by cigwork
Use a primary and secondary sort field. Primary controlled by "Package" and the secondary by the alphabetic order of the other values.insert into sortTest (name) values('Package')insert into sortTest (name) values('Crime')insert into sortTest (name) values('DIC')insert into...
25 Nov 2015 by CodeGust
I must create a console autocomple app that uses a file with stats of each word:paper 223morning 114motor 513degree 22There about 100000 words+What is the best way (/algorithm) for doing that?I am thinking of writing words of each first letter to a separate key-value List...
15 Jan 2013 by Coder93
what comb sort and shell sort exactly do?
16 Jan 2014 by Codes Of Shadows
Header Style Combo Box Drop Down Filter Button
15 Nov 2013 by Commish13
My question is: Can a DataTable have sorting columns. I want to click on the column headers of my GridView that is being populated by a Fill DataTable code. Every time I try to look up Sorting columns they use a DataSet code. If anyone knows of a tutorial or just an answer if this can be...
15 Nov 2013 by Commish13
Hi. I'm using this code to try and sort my GridView without a DataSource. The problem is I don't think my GridView is getting populated. Whenever I click on the Column header nothing happen. No Error message etc. This is the code I'm using. Please let me know if you need more info from...
18 Nov 2013 by Commish13
I’m trying to implement a Sort feature for my GridView that is being populated from a DataTable. Also I have a Filter/Search feature so I can’t use ViewState cause every time the Filter /Search results are displayed and I try to Sort them the Sort displays all the records then Sorts them....
17 May 2013 by computermagic
Generating sequential GUIDs in C++ and Qt 5
8 Mar 2022 by CoralSpring
after ES6: json.sort((a, b) => a._time) - b._time)); Taken from here: Sorting an array of objects by property values[^]
16 Sep 2013 by CPallini
Of course it is possible.You might, for instance, import the CVS file data into a (in-memory) DataTable and then sort it with a standard SQL query.
20 Dec 2013 by CPallini
Quote:I didn't use any tecniques such as linq, ....I want to do it with available algorithms and arrange the file.One of best sorting algorithms is quicksort[^]. Happy coding.
17 Mar 2014 by CPallini
You may use a dictionary to map the Type Ids to your own order criterion, e.g.Dictionary mo = new Dictionary{ { 3, 0 }, { 5, 1 }, {2,2}, {4,3}, {6,4} };Thendocuments.OrderBy(d => mo[d.Type.Id])