list.sort

通过对提供的数组进行就地修改来返回已排序的数组。因此,元素数组将被修改。

numpy.sort(ndarray.sort与之类似)

使用numpy.sort函数可以对数组进行排序,并返回排序好的数组。

  • 语法

    numpy.sort(a, aixs=-1, kind=None, order=None)
    
  • 参数

    numpy.sort(a, axis=1, kind='quicksort', order=None)
    Parameters: a : array_likeArray to be sorted.axis : int or None, optionalAxis along which to sort. If None, the array is flattened before sorting. The default is 1, which sorts along the lastaxis.kind : {‘quicksort’, ‘mergesort’, ‘heapsort’}, optionalSorting algorithm. Default is ‘quicksort’.order : str or list of str, optionalWhen a is an array with fields defined, this argumentspecifies which fields to compare first, second, etc. A single field can be specified as a string, and not all fields need be specified, but unspecified fields will still be used, in the order in which they come up in the dtype, to break ties.
    Returns:    sorted_array : ndarrayArray of the same type and shape as a.
    • a 要排序的数组
    • axis 按什么轴进行排序,默认按最后一个轴进行排序。
    • kind 排序方法,‘quicksort’为快排,‘mergesort’为混排,‘heapsort’为堆排,默认是快速排序
    • order 当数组定义了字段属性时,可以按照某个属性进行排序。
  • 例子

    import numpy as np
    # 创建一个一维数组
    x1 = np.array([1,8,2,4])
    x1
    '''
    一维数组:
    array([1, 8, 2, 4])
    '''
    # 排序
    np.sort(x1)
    '''
    输出:
    array([1, 2, 4, 8])
    '''# 创建一个二维数组
    x2 = np.array([[1,8,2,4],[4,5,1,3]])
    x2
    '''
    二维数组:
    array([[1, 8, 2, 4],[4, 5, 1, 3]])
    '''
    # 默认按最后一个轴排序,这里按行排序
    np.sort(x2)
    '''
    输出:
    array([[1, 2, 4, 8],[1, 3, 4, 5]])
    '''
    # 轴设为0,即按列排序
    np.sort(x2,axis=0)
    '''
    输出:
    array([[1, 5, 1, 3],[4, 8, 2, 4]])
    '''
    

    按照字段属性进行排序,需要用到order参数。

    import numpy as np
    # 这是一个名字、身高、年龄的数组
    # 先给各字段配置属性类型
    dtype = [('Name', 'S10'), ('Height', float), ('Age', int)]
    # 各字段值
    values = [('Li', 1.8, 41), ('Wang', 1.9, 38),('Duan', 1.7, 38)]
    # 创建数组
    a = np.array(values, dtype=dtype)
    a
    '''
    数组:
    array([(b'Li', 1.8, 41), (b'Wang', 1.9, 38), (b'Duan', 1.7, 38)],dtype=[('Name', 'S10'), ('Height', '<f8'), ('Age', '<i4')])
    '''
    # 按照属性Height进行排序,此时参数为字符串
    np.sort(a, order='Height')
    '''
    输出:
    array([(b'Duan', 1.7, 38), (b'Li', 1.8, 41), (b'Wang', 1.9, 38)],dtype=[('Name', 'S10'), ('Height', '<f8'), ('Age', '<i4')])
    '''
    # 先按照属性Age排序,如果Age相等,再按照Height排序,此时参数为列表
    np.sort(a, order=['Age', 'Height'])
    '''
    输出:
    array([(b'Duan', 1.7, 38), (b'Wang', 1.9, 38), (b'Li', 1.8, 41)],dtype=[('Name', 'S10'), ('Height', '<f8'), ('Age', '<i4')])
    '''
    


sorted

对所有可迭代的对象进行排序操作。返回排序后的数组,而不修改原始数组。

  • 语法

    sorted(iterable, cmp=None, key=None, reverse=False)
    
  • 参数说明

    • iterable 可迭代对象
    • cmp 比较的函数,这个具有两个参数,参数的值都是从可迭代对象中取出,此函数必须遵守的规则为,大于则返回1,小于则返回-1,等于则返回0.
    • key 主要是用来进行比较的元素,只有一个参数,具体的函数的参数就是取自于可迭代对象中,指定可迭代对象中的一个元素来进行排序。
    • reverse 排序规则,reverse=True降序,reverse=False升序(默认)。
  • 例子

sort函数与sorted函数最大的区别是:

  • sort函数对已存在的列表进行操作,调用其没有返回值。
  • 内置函数sorted方法返回一个新的list,不在原来的list上进行操作,调用其返回一个排好序的list。

numpy.argsort

numpy中的argsort函数用于将数组排序后,返回数组元素从小到大依次排序的所有元素索引。返回排序数组的索引,而不是数组元素的索引。

  • 语法

    numpy.argsort(a, axis=-1, kind=None, order=None)
    
  • 参数

    numpy.argsort(a, axis=1, kind='quicksort', order=None)
    Parameters: a : array_likeArray to sort.axis : int or None, optionalAxis along which to sort. The default is 1 (the last axis).If None, the flattened array is used.kind : {‘quicksort’, ‘mergesort’, ‘heapsort’}, optionalSorting algorithm.order : str or list of str, optionalWhen a is an array with fields defined, this argumentspecifies which fields to compare first, second, etc. Asingle field can be specified as a string, and not all fieldsneed be specified, but unspecified fields will still be used,in the order in which they come up in the dtype, to breakties.
    Returns:    index_array : ndarray, intArray of indices that sort a along the specified axis. If ais one-dimensional, a[index_array] yields a sorted a.
    • a 要排序的数组
    • axis 数组排序时的基准,按什么轴进行排序,axis=0按行排列,axis=1按列排列,默认按最后一个轴进行排序
    • kind 排序方法,默认是快速排序
    • order 当数组定义了字段属性时,可以按照某个属性进行排序
  • 例子

    import numpy as np
    # 创建一维数组
    x = np.array([3, 1, 2])
    '''
    数组:
    array([3, 1, 2])
    '''
    # 获取排序后的索引
    np.argsort(x)
    '''
    输出:
    array([1, 2, 0], dtype=int64)
    '''# 创建二维数组
    x2 = np.array([[0, 3], [2, 2]])
    '''
    数组:
    array([[0, 3],[2, 2]])
    '''
    # 默认按照最后一个轴进行排序,即行排序
    # 获取排序后的索引
    np.argsort(x2)
    '''
    输出:
    array([[0, 1],[0, 1]], dtype=int64)
    '''
    

    按字段属性进行排序,并获取索引。

    # 先给各字段配置属性类型
    dtype = [('name', str), ('age', int)]
    # 值
    values = [('Anna', 28), ('Bob', 27),('Brown',21)]
    # 创建数组
    x = np.array(values, dtype=dtype)
    x
    '''
    数组:
    array([('', 28), ('', 27), ('', 21)],dtype=[('name', '<U'), ('age', '<i4')])
    '''
    # 先按照属性age排序,如果age相等,再按照name排序
    np.argsort(x,order=['name','age'])
    '''
    输出:
    array([2, 1, 0], dtype=int64)
    '''
    

    >>>list1=[4,2,5,7,3]
    >>>a=np.array(list1)
    >>>a
    array([4, 2, 5, 7, 3])
    >>>b=np.argsort(a)
    >>>b
    array([1, 4, 0, 2, 3], dtype=int64)
    # 列表b的元素表示的是原列表a中的元素的索引,5各元素的索引分别为0-4
    # 返回的结果可以这样解读:
    #   b[0]=1,表示原列表a的最小元素的索引为1,即原列表a中的第2个元素为最小值
    #   b[1]=4,表示原列表a的第二小元素的索引为4,即原列表a中的第5个元素为第二小元素
    #   ...
    #   b[4]=3,表示原列表a中的最大元素的索引为3,即原列表a中的第4个元素为最大值
    >>>list2=[[3, 2],[5, 7]]
    >>>c=np.array(list2)
    >>>c
    array([[3, 2],[5, 7]])
    >>>np.argsort(c, axis=1)
    array([[1, 0],[0, 1]],dtype=int64)
    # axis=1,表明按照行进行排序,即是对[3, 2]进行排序,所以得到索引为[1, 0],其他同理
    >>>np.argsort(c, axis=0)
    array([[0, 1],[0, 1]],dtype=int64)
    # axis=0,表明按照列进行排序,即是对[3, 5]进行排序,所以得到索引为[0, 1],其他同理
    >>> x = np.array([(1, 0), (0, 1)], dtype=[('x', '<i4'), ('y', '<i4')])
    >>> x
    array([(1, 0), (0, 1)], dtype=[('x', '<i4'), ('y', '<i4')])
    >>> np.argsort(x, order=('x','y'))
    # 先按照x进行比较,再按照y进行比较,即是先比较1与0
    array([1, 0])
    >>> np.argsort(x, order=('y','x'))
    # 先按照y进行比较,再按照x进行比较,即是先比较0与1
    array([0, 1])
    
    a = np.array([[1,2,1,5],[5,3,6,9],[6,2,9,5]])
    #按照第1行对列进行排序
    a1 = a.T[a[0].argsort()].T
    #或者
    a2 = a[:, a[0].argsort()]
    #按照最后1行对列进行排序
    a3 = a.T[a[-1].argsort()].T
    #或者
    a4 = a[:, a[-1].argsort()]
    #按照第1列对行排序
    a5 = a[a[:, 0].argsort()]
    #按照最后1列对行排序
    a6 = a[a[:, -1].argsort()]
    



numpy.lexsort

numpy.lexsort函数用于按照多个条件(键)进行排序,返回排序后索引。使用键序列执行间接稳定排序,用于使用涉及多个数组的多个排序键进行排序。
给定多个排序键(可以将其解释为电子表格中的列),lexsort返回一个整数索引数组,该数组描述按多个列排序的顺序。序列中的最后一个键用于主排序顺序,倒数第二个键用于辅助排序顺序,依此类推。keys参数必须是可以转换为相同形状的数组的对象序列。如果为keys参数提供了2D数组,则将其行解释为排序键,并根据最后一行,倒数第二行等进行排序。

  • 语法

    numpy.lexsort(keys, axis=-1)
    
  • 参数

    • keys 序列或元组,要排序的不同的列
    • axis 沿指定轴进行排序
  • 例子

    import numpy as np
    # 英语成绩
    eng = [90,85,95,80]
    # 数学成绩
    math = [80,95,90,85]
    # 总成绩
    total = [170,170,185,165]
    # 排序,获取索引
    np.lexsort((eng,math,total))
    '''
    先按总成绩total进行排序,
    再按数学成绩math进行排序,
    最后按英语成绩进行排序。
    可以看到total里有两个170,
    这时候就按下一级math排序,
    最后获取排序后的索引
    输出:
    array([3, 0, 1, 2], dtype=int64)
    '''
    # 也可以直接传入数组
    score = np.array([[90,85,95,80],[80,95,90,85],[170,170,185,165]])
    np.lexsort(score)
    '''
    输出:
    array([3, 0, 1, 2], dtype=int64)
    '''
    

    >>> a=[1,5,1,4,3,4,4]
    >>> b=[9,4,0,4,0,2,1]
    >>> np.lexsort((b,a))
    # b在前,a在后,即是先按照a的元素进行比较
    # 如a中的最小值为两个1,其索引分别为0,2,再计较b中相应索引上的值,即9,0
    # 对应的最小应是:1,0,而其对应的索引为2,所以排序后返回的结果第一个值为索引2
    # 下一个最小应是:1,9,而其对应的索引为0,所以排序后返回的结果第一个值为索引0
    # 以此类推...
    array([2, 0, 4, 6, 5, 3, 1], dtype=int64)
    >>> np.lexsort((a,b))
    # a在前,b在后,即是先按照b的元素进行比较
    # 如b中的最小值为两个0,其索引分别为0,4,再计较a中相应索引上的值,即1,3
    # 对应的最小应是:0,1,而其对应的索引为2,所以排序后返回的结果第一个值为索引2
    # 下一个最小应是:0,3,而其对应的索引为4,所以排序后返回的结果第一个值为索引4
    # 以此类推...
    array([2, 4, 6, 5, 3, 1, 0], dtype=int64)
    >>> c=[[1,5,1,4,3,4,4],[9,4,0,4,0,2,1]]
    >>> c
    [[1, 5, 1, 4, 3, 4, 4], [9, 4, 0, 4, 0, 2, 1]]
    >>> np.lexsort(c)
    # 此种情况与先b后a的情况一致
    array([2, 4, 6, 5, 3, 1, 0], dtype=int64)

实现对数组或列表按照某一行或列进行排序。按照一个键值序列提供一个间接稳定的排序。

lexsort(keys, axis=-1)
  • 利用lexsort对二维数组按照某一行排序
    lexsort的键参数是二维数组时,对行排序,排序的方式是先对最后一行排序,当有相同元素时,然后按照倒数第二行对应的元素排序,……依次类推。
    例如:a1返回的是a的最后一行按照从小到大排列后所对应的索引值,比如最后一行为[6,2,9,5],从小到大排列为:2,5,6,9;其对应的索引号为:1,3,0,2.
    如果对a按照第二行升序排列,当有相同项时按照第一行升序排序.

    import numpy as np
    a = np.array([[1,2,1,5],[5,3,6,9],[6,2,9,5]])
    a.shape
    a
    #对a按照最后一行排序
    a1 = np.lexsort(a)
    a1
    a.T[a1].T
    #或者
    a[:, a1]
    #对a按照最后一行排序2
    a4 = np.lexsort(a[-1, None])
    a4
    a.T[a4].T
    #对a按照第二行升序排列,当有相同项时按照第一行升序排序
    a2 = np.lexsort(a[0:2, :])
    a2
    a.T[a2].T
    #或者
    a[:, a2]
    #对a按照第一行排序
    a3 = np.lexsort(a[::-1, :])
    a3
    a.T[a3].T
    #或者
    a[:, a3]
    #对a按照第一行排序2
    a5 = np.lexsort(a[0, None])
    a5
    a.T[a5].T
    





  • 利用lexsort对二维数组按照某一列排序
    只需将数组矩阵做转置,将列变成行,行变成列就可以了。例如:对a矩阵按照第二列升序排列,当遇到相同元素时按照第一列升序排列。首先对a矩阵装置,这样矩阵的列变成了行,然后在对行按照第二行升序的方式排列,都获取相应的序列编号。

       a = np.array([[1,2,1,5],[5,3,6,9],[6,2,9,5]])a.shapea#按最后一列顺序排序a1 = np.lexsort(a.T)a1a[a1]#或者a[a1, :]#按最后一列顺序排序2a5 = np.lexsort(a.T[-1, None])a5a[a5]#按最后一列逆序排序a2 = np.lexsort(-a.T)a2a[a2]#或者a[a2, :]#按第二列升序排序,当遇到相同元素按照第一列升序排列a3 = np.lexsort(a.T[:2, :])a3a[a3]#或者a[a3, :]#按照第一列排序a4 = np.lexsort(a[:, ::-1].T)a4a[a4]#或者a[a4, :]#按照第一列排序2a6 = np.lexsort(a.T[0, None])a6a[a6]
    





numpy.searchsorted

给定升序数组以及待插入元素,返回保持序列有序的插入位置。

  • 语法

    numpy.searchsorted(a, v, side='left', sorted=None)
    
  • 参数

    numpy.searchsorted(a, v, side='left', sorter=None)
    Parameters:     a : 1-D array_likeInput array. If sorter is None, then it must be sorted inascending order, otherwise sorter must be an array ofindices that sort it.v : array_likeValues to insert into a.side : {‘left’, ‘right’}, optionalIf ‘left’, the index of the first suitable location foundis given. If ‘right’, return the last such index. If there is no suitable index, return either 0 or N (where N is the length of a).sorter : 1-D array_like, optionalOptional array of integer indices that sort array a intoascending order. They are typically the result of argsort.
    Returns:        indices : array of intsArray of insertion points with the same shape as v
    • a 所需排序的数组
    • v 待查询索引的元素值
    • side 查询索引时的方向,其中kind=left为从左至右,kind=right为从右至左
    • sorder 一个字符串或列表,可以设置按照某个属性进行排序
  • 例子

    >>> list3=[1,2,3,4,5]
    >>> np.searchsorted(list3,2)
    1
    # 如若要在list3中插入元素2,则应当将其插在原列表索引为1的地方,即是插在元素1的后面
    >>> np.searchsorted(list3,[-5,7,4,9])
    array([0, 5, 3, 5], dtype=int64)
    # 如若要在list3中插入元素-5,则应当将其插在原列表索引为0的地方,即是插在元素1的前面
    # 其他以此类推...
    

numpy.partition

返回数组沿指定轴分区/部分排序的副本。排序后的数组副本第k个位置的元素的值不小于其左边元素的值,不大于其右边元素的值。也就是说,返回的数组副本的第k个位置的元素位于正确的有序位置。
把所有元素中按大小排第k位的元素放在排序结果的第k位,比它小的放在前面,比它大的放在后面

  • 语法

    numpy.partition(a, kth, axis=-1, kind='introselect', order=None)
    
  • 参数

    numpy.partition(a, kth, axis=-1, kind='introselect', order=None)
    Parameters:     a : array_likeArray to be sorted.kth : int or sequence of intsElement index to partition by. The k-th value of theelement will be in its final sorted position and all smaller elements will be moved before it and all equal or greater elements behind it. The order all elements in the partitions is undefined. If provided with a sequence of k-th it will partition all elements indexed by k-th of them into their sorted position at once.axis : int or None, optionalAxis along which to sort. If None, the array is flattenedbefore sorting. The default is -1, which sorts along the last axis.kind : {‘introselect’}, optionalSelection algorithm. Default is ‘introselect’.order : str or list of str, optionalWhen a is an array with fields defined, this argumentspecifies which fields to compare first, second, etc. A single field can be specified as a string. Not all fields need be specified, but unspecified fields will still be used, in the order in which they come up in the dtype, to break ties.
    Returns:        partitioned_array : ndarrayArray of the same type and shape as a
    • a 待排序的数组或类似数组的对象
    • kth 第k个位置,可指定多个位置
    • axis 待排序的轴,axis=None,将所有元素排序,返回一维数组;axis为其它整数值,则沿着指定轴排序,默认值-1,沿最后一个轴排序
    • kind 排序方法
    • order 用于指定字段的结构化数组排序的参数
  • 例子

    >>>list=[3,4,5,2,1]
    >>>np.partition(list,3)
    array([2, 1, 3, 4, 5])
    # 以排序后的第3个数,即3进行分区,分区后的结果即是:
    # 小于3的元素2,1位于3的前面,大于等于3的元素4,5位于3的后面
    >>>a = np.array([[3, 4, 2, 1],[7,5,6,8]])
    >>>np.partition(a,kth=3,axis=1)# along the sencond axis (column)
    array([[2, 1, 3, 4],[6, 5, 7, 8]])
    >>>np.partition(a,kth=0,axis=0)# along the first axis (row)
    array([[3, 4, 2, 1],[7, 5, 6, 8]])
    

    >>> a = np.array([ 8, 10,  3,  2, 14, 9,  7, 11,  0, 13, 6,  1,  5,  4, 12, 15])
    >>> np.partition(a, 4)# 第4个位置的元素位于正确有序元素,即元素4位于有序位置
    array([ 2,  0,  1,  3,  4,  5,  6, 10,  7,  8,  9, 11, 13, 14, 12, 15])
    >>> np.partition(a, (4,12))    # 第4和12个位置的元素位于正确有序位置
    array([ 2,  0,  1,  3,  4,  5,  6, 10,  7,  8,  9, 11, 12, 14, 13, 15])
    a = np.asarray([np.random.randint(0,20, 10) for _ in range(10)])
    >>> a = np.asarray([np.random.randint(0,10, 10) for _ in range(5)])
    >>> a
    array([[1, 0, 2, 2, 0, 1, 7, 3, 6, 9],[9, 8, 0, 2, 8, 2, 0, 2, 6, 9],[2, 6, 3, 5, 5, 7, 7, 3, 2, 2],[3, 2, 7, 8, 5, 1, 2, 1, 3, 1],[4, 0, 1, 4, 3, 2, 2, 3, 9, 7]])
    >>> np.partition(a, 2, axis=0)    # 对各列分区排序,结果第2行为分界线
    array([[1, 0, 0, 2, 0, 1, 0, 1, 2, 1],[2, 0, 1, 2, 3, 1, 2, 2, 3, 2],[3, 2, 2, 4, 5, 2, 2, 3, 6, 7],[9, 6, 7, 8, 5, 7, 7, 3, 6, 9],[4, 8, 3, 5, 8, 2, 7, 3, 9, 9]])
    >>> np.partition(a, 5, axis=1)        # 对各行分区排序,结果第5列为分界线
    array([[0, 0, 1, 1, 2, 2, 3, 6, 7, 9],[2, 2, 0, 0, 2, 6, 8, 8, 9, 9],[2, 2, 2, 3, 3, 5, 5, 6, 7, 7],[1, 1, 1, 2, 2, 3, 3, 8, 7, 5],[0, 1, 2, 2, 3, 3, 4, 4, 9, 7]])
    

numpy.argpartition

返回数组沿指定轴分区/部分排序的索引数组。索引数组中位置k的索引对应的元素不小于位置k之前索引对应的元素,不大于位置k之后索引对应的元素。

  • 语法

    numpy.argpartition(a, kth, axis=-1, kind='introselect', order=None)
    
  • 参数

    • a待排序的数组或类似数组的对象索引
    • kth 第k个为在,可指定多个位置
    • axis 待排序的轴,axis=None,将所有元素排序,返回一维数组;axis为其它整数值,则沿着指定轴排序,默认值-1,沿最后一个轴排序
    • kind 排序方法
    • order 用于指定字段结构化数组排序的参数
  • 例子

    >>> a = np.array([ 8, 10,  3,  2, 14, 9,  7, 11,  0, 13, 6,  1,  5,  4, 12, 15])
    >>> np.argpartition(a, 4)
    array([ 3,  8, 11,  2, 13, 12, 10,  1,  6,  0,  5,  7,  9,  4, 14, 15],dtype=int64)
    >>> np.argpartition(a, (4,12))
    array([ 3,  8, 11,  2, 13, 12, 10,  1,  6,  0,  5,  7, 14,  4,  9, 15],dtype=int64)
    >>> a[np.argpartition(a, (4,12))]  # 等价于np.partition(a, (4,12))
    array([ 2,  0,  1,  3,  4,  5,  6, 10,  7,  8,  9, 11, 12, 14, 13, 15])
    

参考资料

1.sorted()、sort()函数
2.Python中的a.sort,sorted(a),np_argsort(a)和np.lexsort(b,a)
3.Numpy进阶之排序小技巧
4.numpy排序(sort、argsort、lexsort、partition、sorted)
5.Python——numpy排序(sort、argsort、lexsort、partition、sorted)
6.numpy sort/argsort, lexsort,sort_complex,partition
7.numpy中二维数组按照某列、某行排序
8.numpy排序(sort、argsort、lexsort、partition、sorted)
9.NumPy 排序函数
10.Numpy数组的排序与选择:sort, argsort, partition, argpartition, searchsorted, lexsort等
11.numpy排序(sort、argsort、lexsort、partition、sorted)
12.NumPy排序,搜索和计数功能
13.python基于numpy的多维数组排序

排序函数(sort、sorted、argsort、lexsort、partition、argpartition、searchsorted)相关推荐

  1. python 排序函数 sort sorted 简介

    sort() 是Python列表的一个内置的排序方法,list.sort() 方法排序时直接修改原列表,返回None: sort() 是Python内置的一个排序函数,它会从一个迭代器返回一个排好序的 ...

  2. C++ 排序函数 sort(),qsort()的用法

    想起来自己天天排序排序,冒泡啊,二分查找啊,结果在STL中就自带了排序函数sort,qsort,总算把自己解脱了~ 所以自己总结了一下,首先看sort函数见下表: 函数名 功能描述 sort 对给定区 ...

  3. R语言数据排序函数sort, order rank实战

    R语言数据排序函数sort, order & rank实战 目录 R语言数据排序函数sort, order & rank实战 #sort vs. order vs. rank函数基础 ...

  4. 排序函数(sort()、sorted()、argsort()函数)

    python的内建排序函数有 sort.sorted两个. 1.基础的序列升序排序直接调用sorted()方法即可 1 ls = list([5, 2, 3, 1, 4]) 2 new_ls = so ...

  5. 排序函数 sort()、sorted()、argsort()函数

    sort()函数 python的内建排序函数有 sort.sorted两个.而sort ()可以直接对列表进行排序 用法:list.sort(func=None, key=None, reverse= ...

  6. python 数组排序sort_Python之排序函数sort() 和 sorted()

    sort() 是Python列表的一个内置的排序方法,list.sort() 方法排序时直接修改原列表,返回None: sort() 是Python内置的一个排序函数,它会从一个迭代器返回一个排好序的 ...

  7. 指针:调用自定义排序函数sort,对输入的n个数进行从小到大输出。

    Description 自定义函数sort(int *p, int n),功能是对n个数排序.在main函数中,调用它,对输入的任意个数排序. Input 多组测试数据,先输入n(n<100), ...

  8. php中asort 排序语句,php中的几个经典排序函数(sort,asort,ksort等)

    1 2 3 4 5 6 7 8sort() 函数用于对数组单元从低到高进行排序. rsort() 函数用于对数组单元从高到低进行排序. asort() 函数用于对数组单元从低到高进行排序并保持索引关系 ...

  9. c++自带的排序函数sort

    其实C语言里也有qsort排序函数,但相较于C++的sort排序函数更加繁琐,不推荐使用.下面来介绍怎么使用C++里的sort排序函数. Sort的用法 1.sort函数的使用必须加上头文件#incl ...

  10. matlab排序函数——sort

    直接对某一向量进行排序B=sort(A),得到的B就是对A升序排序的结果: B=sort(A,'descend'),是对A进行降序排序的结果 [B,C]=sort(A),B是对A中元素进行升序排序的结 ...

最新文章

  1. 架构语言ArchiMate -业务层(Business Layer)
  2. MySQL 高级 - 存储过程 - 语法 - while循环
  3. 注意语句顺序 防止Servlet Request Response乱码
  4. VC++下命名管道编程的原理及实现
  5. 搜索引擎排名不友好的五个地点-SEO
  6. 金融统计分析与挖掘实战3.1-3.2
  7. T4模板——一个神奇的代码生成器
  8. [沫沫金原创]Sql中跨库访问和同库跨用户访问区别
  9. python之类之多继承
  10. linux安装weget命令,linux安装wget命令
  11. 华为云obs对象存储使用教程
  12. 照片调色系列教程(一):打造格调美女
  13. 程序员初学者如何自学编程
  14. 奔跑吧恐龙----基于JavaSwing的一个跑酷游戏
  15. php扇形统计图怎么做,PHP实现绘制3D扇形统计图及图片缩放实例_php实例
  16. 数据结构课设(散列表的设计与实现---电话号码查找系统)
  17. 大数据HBase(四):HBase的相关操作-客户端命令式
  18. 【转载】BLE安全机制从入门到放弃
  19. 用科学计算机打游戏,10个惊人的游戏,竟然有助于科学研究,你玩过几个?
  20. 逃离天坑之后——谈谈技术路线该怎么走

热门文章

  1. .NET framework 是什么? 有何意义?
  2. 程序员如何成功的假装在很努力的工作
  3. UCSB云计算之Eucalyptus
  4. c++11 智能指针-辅助类 (std::bad_weak_ptr)
  5. Structured Streaming-快速入门
  6. 如何联系Github作者
  7. 为什么百度查到的ip和ipconfig得到的ip不同
  8. 白话讲解UML的4大关系:关联关系、泛化关系、依赖关系、实现关系
  9. java毕业生设计校园讲座管理计算机源码+系统+mysql+调试部署+lw
  10. java process destory_Java Process destroy()方法