首页 > 其他分享 >sort

sort

时间:2022-11-16 07:33:07浏览次数:32  
标签:sort arr mindx temp min idx jdx

package com.challenger;

import com.challenger.Util;

public class SelectSort
{
    public static void main(String[] args)
    {
        int[] arr={5,8,6,3,1,4,10,9,2,7};
        int i,idx,min,mindx,j,jdx,temp;

        for(i=1;i<=arr.length-1;i++)
        {
            idx=i-1;
            min=i;
            mindx=min-1;
            for(j=min+1;j<=arr.length;j++)
            {
                jdx=j-1;
                if(arr[jdx]<arr[mindx])
                {
                    min=j;
                }
                else
                {
                }
            }
            temp=arr[idx];
            arr[idx]=arr[mindx];
            arr[mindx]=temp;
        }
        Util.printArray(arr);


    }
}

标签:sort,arr,mindx,temp,min,idx,jdx
From: https://www.cnblogs.com/lsjava/p/16894670.html

相关文章

  • 1710. 卡车上的最大单元数 ----- 贪心算法,自定义sort排序
    请你将一些箱子装在一辆卡车上。给你一个二维数组boxTypes,其中boxTypes[i]=[numberOfBoxesi,numberOfUnitsPerBoxi]:numberOfBoxesi是类型i的箱子的数量。numb......
  • Minimum Number of Operations to Sort a Binary Tree by Level
    MinimumNumberofOperationstoSortaBinaryTreebyLevelYouaregiventhe root ofabinarytreewithuniquevalues.Inoneoperation,youcanchooseany......
  • C++中sort函数、1.4最长公共子串
    sort()即为用来排序的函数,它根据具体情况使用不同的排序方法,效率较高。sort在实现时避免了经典快速排序中可能出现的会导致实际复杂度退化到O(n2)的极端情况。使用sort()......
  • 75.Sort Colors
    Givenanarraywith n objectscoloredred,whiteorblue,sortthemsothatobjectsofthesamecolorareadjacent,withthecolorsintheorderred,white......
  • 791. 自定义字符串排序 ----- 自定义sort、权值排序、计数排序
    给定两个字符串order和s。order的所有单词都是唯一的,并且以前按照一些自定义的顺序排序。对s的字符进行置换,使其与排序的 order 相匹配。更具体地说,如果在 or......
  • Java:自定义排序与sort()函数
    自定义排序与Arrays.sort()本篇题目来源:2022/11/13Leetcode每日一题:https://leetcode.cn/problems/custom-sort-string给定两个字符串order和s。order的所有单词都......
  • AtCoder Beginner Contest 277 F Sorting a Matrix
    SortingaMatrix拓扑序首先可以明确无论怎么交换行列,原本在同一行或者同一列的元素,还是会处于同一行或者同一列条件一每行每行地看,如果能满足从小到大的条件,说明第......
  • Sort List
    SourceSortalinkedlistinO(nlogn)timeusingconstantspacecomplexity.题解1-归并排序(链表长度求中间节点)链表的排序操作,对于常用的排序算法,能达到O(n......
  • Redis有序集合Zset(sorted set)
    Redis有序集合zset与普通集合set非常相似,是一个没有重复元素的字符串集合。不同之处是有序集合的每个成员都关联了一个评分(score),这个评分(score)被用来按照从最低分到最高......
  • heap sort
    privatevoidbuildHeap(int[]h){intl=h.length;//这里需要从下向上调整,因为从上向下调整只能让最小值下到底端,只有从下向上调整可以让最大值......