Sorting Algorithms

Sorting algorithms:

Def: are used to arrange the data into some order.(以某种特定的方式排列数据)

Bubble Sort:

Def: to arrange the data to ascending or descending order. (以升序或者降序的方式排列数据)

Insertion sort algorithm:

Def: begin by looking at the first two elements of the array.We compare these elements and, if necessary, we swap them so they are in the proper order.Then, our objective is to incorporate the third element of the array into the part of the array already sorted. We do this by inserting it into proper position, relative to the first two elements. If we need to shift either of the first two elements to accommodate the third element, we do so. Once we have inserted the third element into the correct position (relative to the first two elements), the initial portion of the array consisting of the first three elements will be sorted.
1.给前两个元素排序,

2.将数组的第三个元素插入到前两个元素中适当的位置。把它合并到已经排序的数组中。

如果我们需要移动前两个元素中的任何一个来容纳第三个元素,我们就这样做。一旦我们将第三个元素插入到正确的位置(相对于前两个元素),由前三个元素组成的数组的初始部分将被排序。

selection sort algorithm:

Def: The selection sort works like this: The smallest value in the array is located and moved to position 0. Then, the next smallest value is located and moved to position 1. This process continues until all of the elements have been placed in their proper order. Let's see how the selection sort works when arranging the elements of the array in Figure 17-8.
1.对数组中最小的值进行定位,并将其移动到位置0。

2.再定位下一个最小值,并移动到位置1。

循环以上过程,直到所有元素都按适当的顺序放置。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值