Bubble sort is a sort of exchange in which the size of adjacent two elements is constantly compared, and if the condition (increment or decrement) is met, the position of the adjacent two elements is exchanged.Bubble sort is relatively simple, it does not have to be elaborated, the code is implemented as follows:#inclu
bubble sorting algorithm time complexity with the above selection sort is a type, so below I only about the description below:Bubble Sort:About the bubble sort, the name is actually more interesting, remember when you often throw stones to the small ditch, every time we throw a stone, you will find that there will be
fewer elements, until there is no pair of numbers to compare.
var arr=[2,5,1,0,10,20,4];function ABC2 (arr) {for (var i=0;iarr. length;i++) {for (Var j=0;jarr=tocon (arr,j) } } return arr;} function Tocon (arr,index) { if (Arr[index]>arr[index+1]) { var a=arr[index+1]; Arr[index+1]=arr[index]; arr[index]=a; } return arr;} Alert (ABC2 (arr))Select Sort:Select sort (Selection
#include Analysis: The advantages and disadvantages of bubble sorting are as follows:1. Best case: Time complexity of O (n)2. Worst sensibility: Time complexity of O (n squared)So this sort of existence is uncertain and usually inefficient.Sort--bubble sort
First, bubble sortFirst outer loop (i=0): N number is not sorted, to compare n-1 timesSecond outer loop (I=1): n-1 number is not sorted, to compare n-2 timesN-1 Outer Loop (i=n-2): 2 left unsorted, to compare 1 times(1+2+...+n-1) =n (n-1)/2METHOD1:After each outer loop, there is a large number of sink. Public Static voidMETHOD1 (int[] Array) { intn=Array.Length; for(inti = 0; i ) { for(intj = 0; J ){ if(Array[
Select sortvoid test2 (int a[],int len) {Each time a minimum value is found, the minimum value is followed by the original array exchange position, through the subscript to complete the exchange, the minimum subscript is changed every time, variable storageIf the first one is the minimum valueint mine=0;int teamp=0;The outer is responsible for the number of tripsfor (int i=0; iIf the first of each is a minimum valueMine=i;The inner layer is responsible for finding the minimum value per trip.Each
1 Select sort is a "0" is compared with the following elements, if it is smaller than a "0", then swap, so that the smallest value is found.Then a "1" is compared with the following elements, if the ratio of "1" is small, then the exchange so as to find the second small value.Cycle down, you can achieve the sort.The Java code is as followspublic static void sort (int[] arr)//select
Bubble Sort Method
Topic Description:
Use a one-dimensional array to store the number and score, and then sort the output by grade.
Input:
Enter the first line to include an integer N (1The next n rows consist of two integers p and q, representing each student's number and grade, respectively.
Output:
According to the students ' grades from small to large t
mood: Someone asks, what kind of person do you want to be? I am 23 years old this year, senior last semester, I am very confused .
Arrays can have more than one line, but this is a table image; there's no branch in memory. This is supposed to be segmented
Is bubbling a bubble rising to the top in an internal traversal? "If that's the case, what sort of selection is it?" 】
The one-time trave
Basic idea:Set the number of elements in the sequence of data elements to be sorted n, up to n-1, i = 1, 2, ..., n-1. In the first trip from the back forward, j = n-1, N-2, ..., I, 22 compare v[j-1] and v[j] keywords. Swap v[j-1] and v[j] if reverse is occurring.#include voidprintlnintArray[],intLen) { inti =0; for(i=0; i) {printf ("%d", Array[i]); } printf ("\ n");}voidSwapintArray[],intIintj) { inttemp =Array[i]; Array[i]=Array[j]; ARRAY[J]=temp;}voidBubblesort (intArray[],intLen//O (n*
Quick Sort Method1. Find a datum point2. Create two arrays to store the left and right arrays, respectively3. Use recursion for next comparisonfunction Quictsort (arr) {if (arr.length return arr;}var left = [];var right = [];var num = Math.floor (ARR.LENGTH/2); Find the number in the middle of the array, if even, because it is rounded down so that the previous onevar numvalue = Arr.splice (num,1);for (var i = 0; I if (Arr[i] Left.push (Arr[i]);}else{R
Believe that most people first learn the sort is bubble sort , but the actual application, may be mistakenly written into the insertion sort. Because these two sort algorithms are so much alike, they are brothers.Algorithm name worst time complexity average time complexity o
In js, it is really not a simple task to let the thread sleep. using too many timers or callback functions will make it complicated and messy, you can consider whether the queue can be used for some simplicity. In some scenarios, the queue is indeed like a vanguard, which can bring good results. For example, when used with a timer, the time difference effect can be simulated.
The Code is as follows:
Function createDq (){Var dq = [], size = 0;Return {SetDq: function (queue ){Dq = queue;Size =
, if the condition is met to exchange element values, the difference bubble sort, not the exchange of adjacent elements, but rather the conditions of the elements to the specified position and the order of the exchange. Public classZuoye18_zhijiepaixu { Public Static voidMain (string[] args) {int[] Array =New int[]{2,4,5,123,55,667,32,356}; intindex; for(inti=1;i) {Index=0; for(intj=1;j){ i
1 /**2 * Bubble Sort:3 * Two two comparisons, the biggest one after the last.4 * The number of n becomes a n-15 * One more round6 * The second largest is in the penultimate one.7 * etc.8 * Until the first one9 *Ten * Get two loops, compare two adjacent numbers One */ A Public classBubblesort - { - /** the * Bubble Sor
Bubble sortThought: An array of double loops, judging the left and right adjacent to the two values, large at the left of the small, if the left is larger than the right, the two sides replace the positionThe length of the array is reduced by one because the array starts with 0, for example an array has 7 elements, and its length is 7, respectively.A[0],A[1],A[2],A[3]A[4],A[5],A[6] These 7 so when you want to take the last a[6 in the array, you need t
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.