I have a list of my custom objects. The object contains 1 string and 2 decimals. I would like to sort the list based on the 2nd decimal field descending then the first decimal field.
For eg:
object 1 -> "a", 100, 10
object 2 -> "b", 300, 0
object 3 -> "c", 200, 200
object 4 -> "b", 400, 0
would be sorted as object 3, object 1, object 4, object 2
I apologize if this has already been answered - please point me to that post as I could not find it
Merge sort is often preferred for sorting a linked list. The slow random-access performance of a linked list makes some other algorithms (such as quicksort) perform poorly, and others (such as heapsort) completely impossible.
Below is a simple insertion sort algorithm for a linked list. 1) Create an empty sorted (or result) list 2) Traverse the given list, do following for every node. ......a) Insert current node in sorted way in sorted or result list. 3) Change head of given linked list to head of sorted (or result) list.
Selection sort first finds the smallest element in the unsorted array and swaps it with the first element. Then it finds the second smallest element in the unsorted array and swaps it with the second element, and the algorithm keeps doing this until the entire array is sorted.
Quicksort. Quicksort is one of the most efficient sorting algorithms, and this makes of it one of the most used as well. The first thing to do is to select a pivot number, this number will separate the data, on its left are the numbers smaller than it and the greater numbers on the right.
list.OrderByDescending(o => o.Field2)
.ThenByDescending(o => o.Field1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With