Hill, sort, sortHill sort was a type of insert sort, also known as "shrink increment sort." It was a more efficient and improved version of the direct insert sort algorithm. It was an unstable sort algorithm. It was proposed by D.L.Shell in 1959.
The basic principle of Hill's sorting was to group the records according to a certain increment of the index, and use the direct insert sorting algorithm to sort each group. As the increment gradually decreased, each group contained more and more keywords. When the increment decreased to 1, the entire document was divided into one group, and the algorithm stopped. For example, the original sequence to be sorted was first divided into many small sequences (sub-sequences). Since there were fewer elements in each sub-sequence, it was more efficient to directly insert these sub-sequences. This process could be done many times, and each time was called a pass. Each pass divided the entire sequence obtained from the previous pass into different sub-sequences and directly inserted the sub-sequences again. Finally, when all the elements in the sequence were basically in order, the sequence would be completed by inserting the sequence one last time.
How to sort vegetablesThe specific steps of vegetable sorting included picking, alignment, tying, and basket. First, they placed the vegetables on the processing table and picked out the damaged, crushed, rotten, and deformed parts. Then, he used both hands to stamp the goods on the processing table to make them aligned. Next, he used green tape to tie a piece of cloth from the root. The tightness was just enough for his fingers to insert. Finally, after passing the inspection, they carried out the basket filling operation. Eight vegetables were placed on each layer, and each basket weighed about 10kg. The above was the basic process of sorting vegetables.
Descending sort buttonThere are many ways to find the descending sort button in excel:
1. In the Start tab, he found and clicked on the "sort and filter" option. In the pop-up selection menu, he clicked on the "descending" option to sort. After that, a sort reminder dialog box would pop up. He could choose "expand the selected area" and click the sort button.
2. After selecting the data area that he wanted to sort, he clicked on the "Data" tab, selected the "sort and filter" button, and then selected the "descending order" option.
3. If the version of Excel used was 365, you could also use a function formula to achieve descending sort. For example, you could use the SORT function, such as =SORT(data source,(sort index), -1,(whether to sort by column)), where-1 means descending sort (except for the first argument, the other arguments can be omitted. The second argument specify the sort index, if omitted, the default is 1, the fourth argument specify the sorting method, True is to sort by column, False is to sort by row, the default is False).
Descending sort method以下是一些降序排序的方法:
1. 在Microsoft Excel中:
- 方法一:在开始选项卡中找到并点击“排序和筛选”,然后在弹出的选择菜单中点击“降序”排序,在弹出排序提醒对话框时选择“扩展选定区域”并点击排序按钮。
- 方法二:如果Excel版本是365,可以使用SORT函数,例如对A2:B12区域根据第2列降序排序,在F2单元格输入公式=SORT(A2:B12,2, - 1)。其中第1参数A2:B12是数据源,第2参数2指定排序依据列的索引号,第3参数 - 1指定排序规则为降序。如果需要对多列进行降序排序,比如首先按语文成绩降序排列;如果语文成绩相等,则再按数学成绩降序排序;如果数学成绩相等,则再按英语成绩降序排序,可以在F2单元格输入公式=SORTBY(A2:D12,B2:B12, - 1,C2:C12, - 1,D2:D12, - 1)。
- 方法三:选中想要排序的数据区域,点击“数据”选项卡,选择“排序和筛选”按钮,再选择“降序”选项。
- 方法四:选中需要进行排序的单元格,在菜单栏里面选择“数据”,选择“降序”,会弹出排序提醒,选择默认排序范围,其他栏的数据都会根据选择进行重排。
2. 在C#中,可以使用冒泡排序算法来实现降序排序。冒泡排序是一个元素依次和相邻元素进行比较(这里进行降序比较)进行交换的排序方法。例如有一个自定义类BobbleSortModel的列表lists,类中有Order属性,要根据Order属性进行降序排序,可以使用如下代码:
- 首先定义冒泡排序方法:
- ```csharp
public static List<T> BubbleSort<T>(List<T> lists, Func<T, int> function)
{
int count = lists.Count;
//循环需要排序的次数
for (int i = 0; i < count - 1; i++)
{
//判断本次循环是否有交换的数据
var isSwapData = false;
for (int j = count - 1; j > i; j--)//从后往前遍历数据 并两两进行比较
{
if (function(lists[j - 1]) < function(lists[j]))//如果前面数据小于后面数据 就交换数据(这里进行的是降序)
{
var temp = lists[j - 1];//临时变量保存前一个数据
lists[j - 1] = lists[j];//将后面的数据赋给前一个数据位置
lists[j] = temp;//将临时变量的数据赋给后一位
isSwapData = true;//标识此次数据进行过交换
}
}
//如果此次数据没有发生交换就代表数据以排序好了
if (!isSwapData)
{
return lists;
}
}
return lists;
}
- ```
- 然后定义BobbleSortModel类并创建列表进行排序:
- ```csharp
public class BobbleSortModel
{
public int Id { get; set; }
public string Name { get; set; }
public int Order { get; set; }
}
var lists = new List<BobbleSortModel>()
{
new BobbleSortModel {Id = 1, Name = "名字1", Order = 4},
new BobbleSortModel {Id = 2, Name = "名字2", Order = 1},
new BobbleSortModel {Id = 3, Name = "名字3", Order = 2},
new BobbleSortModel {Id = 4, Name = "名字4", Order = 5},
new BobbleSortModel {Id = 5, Name = "名字5", Order = 3},
};
ClassHlper.BubbleSort(lists, a => a.Order);
- ```
Quick sort animationQuick sorting uses the idea of divide and conquer. The animation shows the process as follows: First, select an arbitrary reference element pivot in an unordered sequence, and divide the sequence to be sorted into two parts. The first part of the elements is less than or equal to the reference element, and the latter part is greater than or equal to the reference element. For example, there is an array of 29,10,14,37,20,25,44,15. If the leftmost element 29 is selected as the middle point element, the array will be divided into three parts: (0, 14, 15, 20, 25),(29),(44, 37). The middle node 29 has been arranged. Then, the above operations were repeated for the front and back parts respectively using a recursion method. That is, for the left and right sub-arrays, they could select their respective reference values and divide the sub-arrays into the left and right parts. The smaller value was placed on the left and the larger value was placed on the right. This continued until the disordered sequence was arranged into an orderly sequence. Through this continuous division and sorting process, the animation could directly show the rapid sorting process.
Quick sort leetcodeQuicksort was an efficient sorting algorithm. The principle was to divide the records to be sorted into two independent parts by sorting. The keywords of one part of the records were smaller than the keywords of the other part of the records. Then, the two parts of the records were sorted separately to achieve the order of the entire sequence.
In terms of code implementation, there are the following sorting steps: first select the data of the left node as the pivot (reference value), start from the right, traverse the node data to the left (under the premise that the right > left condition is met), if the node data> pivot, continue to move to the left; If the node data <= pivot, assign the data of the current node to the left node, then stop the right traverse and start the left traverse. Starting from the left, traverse the node data to the right (under the premise that the left > right condition is met). If the node data < pivot, continue to move to the right; if the node data>= pivot, assign the current node data to the right node, then stop the left traverse and start the right traverse. When left and right overlap, the traverse ends, and the pivot is assigned to the coincidence node. The left side of the pivot node is the left array, and the right side is the right array. After that, the above steps were performed on the left array and the right array to complete the quick sorting.
In addition, the principle of quick sorting was also applicable when dealing with some related problems in Leetcode (such as the k-th smallest number and k-th largest number in the Leetcode topk problem). However, in different scenarios, it may be necessary to make appropriate adjustments according to the requirements of the question and the characteristics of the data structure. For example, when sorting the linked list, it may not be suitable to use the classic quick sort because the single-directional nature of the linked list is not good to traverse from the back to the front. If additional forward connections are added, additional space is needed.
How to sort story viewers?You could sort them based on their preferences for different story genres. For example, group those who like fantasy separately from those who prefer romance.
2 answers
2024-10-02 04:44
How to sort Marvel comics?One way to sort Marvel comics is by the character or team they feature. You could group all the Spider-Man comics together, for example.
How to Sort Fiction Books?Sorting fiction books could be based on the popularity or critical acclaim of the works. Or, you might organize them by the target audience, such as children's fiction or adult fiction. Another option is to classify them according to the geographical setting of the story.
2 answers
2024-10-13 06:55