varArray = [1,2,3,4,5];//---> Services//Efficiency---> Highest efficiency for an ordered array//Flag true False for(varj = 0; J ){ //-J Reduce the number of comparisons after each sort is completed varIsTrue =true;//if the array itself is ascending, the direct output for(vari = 0; I ){ if(Array[i] > array[i+1]) { vartemp =Array[i]; Array[i]= Array[i+1]; Array[i+1] =temp; IsTrue=false; }} document.write (array); i
1PHP2 //set the request header3 Header("Content-type:text/html;charset=utf-8");4 5 //optimize for bubbling sorting: If an array is passed in or traversed two times6 //It is already lined up and no more sorting is done7 8 ///Examples:9 $arr=Array(1,2,3,6,4,12,1,85,1,3);//WaitSort ArraysTen //$arr = range (1, 10000); One A functionMy_bubble_sort ($arr){ - Var_dump($arr); - the $arr _count=Count($arr); - - //Number of comparisons -
for(inti =1; I 9-1; i++)//9 Number of bubble sort, real bubble sort: 22 comparison, number of trips { for(intj =1; J 9-I.; J + +)//number of { if(A[j] 1]) {temp=A[i]; A[i]= A[j +1]; A[j+1] =temp; } } } for (int i = 0 ; i )//subscri
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
Algorithm-sort-bubble sort 1. -- Linux general technology-Linux programming and kernel information. The following is a detailed description. /*************************************** *************************
Title: bubblesort-1.c
Author:
Time:
Purpose: Bubble sorting method 1
Comment:
Usage: 1, gcc-o bubblesort-1 bubbl
Algorithm-sort-bubble sort 2. -- Linux general technology-Linux programming and kernel information. The following is a detailed description. /*************************************** *************************
Title: bubblesort-2.c
Author:
Time:
Purpose: Bubble sorting method 2
Comment:
Usage: 1, gcc-o bubblesort-2 bubbl
More search can refer to http://www.cnblogs.com/liuling/p/2013-7-24-01.html this is someone else's resources, feel write very full. You can study it carefully. /* Use binary to find the premise that the data is ordered (ascending). */class Halfsearchdemo {public static void main (string[] args) {int[] arr={1,2,3,6,2,3,5,1,8,9,3,5,2};sop ("keyword location:" + Halfsearch_2 (arr,6)); System.out.println ("Hello world!");} public static int halfsearch_2 (int[] arr,int key) {searchsort (arr); int Max
Php bubble sort and exchange sort. Copy the code as follows: $ aarray (11,2, 13,4, 22); $ numcount ($ a); for ($ i0; $ I $ num; $ I ++) {for ($ j0; $ j $ num; $ j ++) {if ($ a [$ I] $ a [$ j]) {$ temp $ a [$ I]; $ a [$ I] $ a [$ j]; $ a [$ j]
The code is as follows:
$ A = array ('11', '2', '13', '4', '22 ');$ Num = count ($ );For ($ I = 0; $ I For ($ j = 0;
Insert sort, bubble sort
Create an ordered array, and then insert it one by one from the unordered array to the ordered array.
Code implementation:
1 public class InsertSort {2 InsertSort (int a []) {3 int length =. length; 4 for (int j = 1; j
Class Program{static void Main (string[] args){Define a one-dimensional arrayInt[] arr = {98,1,6,20,16,9};Determine if an exchange occursBOOL B = false;for (int i = 0; i {for (int j = 0; J {Compare each of the two elements in the arrayif (Arr[j] > arr[j + 1]){If it is established, an exchange occursint tmp = ARR[J];ARR[J] = arr[j + 1];Arr[j + 1] = tmp;B = true;}}if (b = = false)//If no exchange occurs, jump directlyBreak}Console.WriteLine (String. Join (",", arr));//literal string concatenation
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.