寫一個數組從小到大的排序
public static void main(String[] args){
//寫一個數組
int[] intSum={12,234,44,64,34,14};
int pro=0;
for(int i=0;i<intSum.length;i++){
pro=i;
int j=i+1;
int temp=intSum[i];//用temp接收陣列的一個值
for(;j<intSum.length;j++){
if(temp>intSum[j]){
temp=intSum[j];
intSum[j]=temp;
pro=j; //接收最小值返回的索引
}
}
intSum[pro]=intSum[i];
intSum[i]=temp;
System.out.print(intSum[i]+"\t");
}
}
}
相關推薦
寫一個數組從小到大的排序
public class Mode{public static void main(String[] args){//寫一個數組int[] intSum={12,234,44,64,34,14}; int pro=0;for(int i=0;i<intSum.leng
選取10-100之間的10個數字,存入一個數組,並排序
一個數 隨機 調用 定義 -m 函數 實現 == turn //選取10-100之間的10個數字,存入一個數組,並排序//實現該功能函數function randomNub(arr,len,min,max){ //如果給的長度大於取值範圍,則超出提示 if(len&
C++面向對象的學習:寫一個數組類
html ++ iuc collect com 4tb ndt gin 面向對象 凰00盟3NDT73澄F概http://www.zcool.com.cn/collection/ZMTgxNzIzMjg=.html O00W51槐AQ毓攀7柿http://www.zcool
vue : 在vuex裏寫一個數組首尾元素互換的方法
clas imp 變量 store apar swap 相同 for con 不著急上代碼,先想幾個問題。 vuex裏怎麽寫方法? mutation裏寫vuex方法,組件中用commit調用。 數組首尾元素怎麽互換? arr.splice(0, 0, arr
用C語言寫一個數組,實現類似JAVA語言中ArrayList的功能
此程式是在看過郝斌老師的資料結構與演算法的視訊後,自己用C語言實現的。整個程式比較簡單,適合入門資料結構時練手。 #include <stdio.h> #include <stdlib.h> #include <malloc.h> #
C++-------模板類案例:利用類模板寫一個數組類
#pragma once #include <iostream> #include <string> using namespace std; template<class T> class MyArry { public: //建構函式: expli
設計一個getMin功能的棧,如果面試官讓你寫一個數組類,一定不要用指標去管理new出來原生的陣列,那就是在給自己挖坑
//設計實現一個getMin功能的棧 #include <iostream> #include <stack> using namespace std; class GetMinStack { public: void push(int x)
用js實現隨機選取10–100之間的10個數字,存入一個數組,並排序
方法一: <!DOCTYPE html> <html><head><meta charset="utf-8"><title>好好學習天天向上</title><script type="text/j
C++面向物件的學習:寫一個數組類
寫一個數組類,實現相關函式,自定義建構函式能設定陣列大小,獲取陣列長度,獲取陣列的元素, 完成陣列的拷貝建構函式,允許兩個陣列物件互相賦值 #ifndef __MYARRAY_H__ #define __MYARRAY_H__ class Array { public:
js將一個數組徹底打亂排序
開發十年,就只剩下這套架構體系了! >>>
LeetCode 31. Next Permutation 找到一個數組的下一個更大的字典序排序
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement
合並排序,將兩個已經排序的數組合並成一個數組
n) ring 一個數 合並排序 sizeof 並排 names 排序 name #include<iostream> #include<string.h> using namespace std; void MergeArray(int a[]
Codeforces Round #283 (Div. 2) A. Minimum Difficulty【一個數組定義困難值是兩個相鄰元素之間差的最大值。 給一個數組,可以去掉任意一個元素,問剩余數列的困難值的最小值是多少】
分析 options force minimum sta cif als 最小 技術分享 A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 mega
O(n)求一個數組中連續區間和的最大值
return 區間 scan CI spa 最大 %d 區間和 數組 int n, a[5000]; int main(){ scanf("%d", &n); for (int i = 1; i <= n; i++)cin >>
求一個數組中最大值與最小值
div return urn 技術 code include 一個 最小值 array #include <stdio.h> int main() { int array[10]={100,1,40,29,45,22,98,2,83,75};
C#獲取一個數組中的最大值、最小值、平均值
program min bsp max exc 平均值 style 最大 return C#獲取一個數組中的最大值、最小值、平均值 1.給出一個數組 1 int[] array = new int[] { 1,2,4,3,0,-1,34,54
Java 數組 定義一個數組,獲取數組中的最大值和最小值,奇數個數和偶數個數
++ java 偶數 system += 最小值 dem [] style /** * 定義一個數組,獲取數組中的最大值和最小值 奇數個數和偶數個數 * */ package com.xuyigang1234.chp01; public class Demo8 {
將一個數組中的各個元素拼接組合,得到數字最大的組合
將一個數組中的各個元素拼接組合,得到數字最大的組合。 如:int[] arr = new int[5] {1, 26, 56, 894, 5648}; 拼接組合後最大的數為 564
繼續對上一頁的ecah進行 優化,求一個數組的和,最大值,最小值,獲取陣列中的元素,3
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style t
JS寫一個方法,傳入一個數組,返回該陣列的層深
現在我們有一個多維陣列,我們想得到該陣列的層深,即最大維度 如:var arr = [1, [4,[5,6,[7]]], [2,3]] = 0;返回4;那麼我們該怎麼做呢? 核心思想:遞迴,迴圈遍歷 // 這裡傳入兩個引數 // 引數一為陣列 // 引數二為初始陣列的層深 function fo(