:200px;
Text-align:center;
margin-left:100px;
margin-top:20px;
font-size:20px;
}
Then the main function is realized.
Script.js window.onload = function () {var btn = document.getElementById ("resultbtn"); Result Output button var Inputnum = document.getElementById ("number"); Digital input box var resultlbl =document.getelementsbytagname ("label");
The result shows the label Var I,j,temp; Bubble sort var
For the improvement of bubble sort, thanks to Morewindows (Microsoft's most valuable expert), to provide me with such a good idea, I just wrote a full Java version.
/** * * @author Fly/public class Bubblesort {//No thought write exchange sort//not bubble sort, compare not adjacent element public int[] Bubblesort (
Int[] a) {int size = A.length; for (int i = 0; i
Bubble Sort Optimization
Bubble sort IdeaThe inner loop number 22 is compared and exchanged, and the last number becomes the maximum numberOuter loop control cycle times, not the last one to participate in the exchange;
Bubbling improvementsIf the inner loop has not been exchanged once, the array is ordered and the break is direct;no need to recycle;
#include
first, bubble sort
Code implementation:
public class Test_bubblesort {public
static void Main (string[] args) {
int[] arr = {23,56,15,13,36};
Bubblesort (arr);
Print (arr);
}
Bubble sort public
static void Bubblesort (int[] arr) {for
(int i = 0;i
The time complexity of the algorithm is O (n^2), and the space complexity is O (1).
Second, select the sort
Code implementation:
public class te
001
#include
002
#include
003
int main ()
004
{
005
int l[11]={0,70,38,65,97,76,93,1,15,68,64}; 0 do not sort just as sentinels, or temporarily swap space for use.
006
int i=0;
007
printf ("Unordered pre-sequence: \ n");
008
for (i=1;i
009
{
010
printf ("%d",
first, the basic idea:
Bubble sort is a simple sort of commutative class. The basic idea is to scan the elements that are to be sorted from scratch, to compare the adjacent elements in sequence during the scan, and to move the elements of the key value back. After each trip, the element with the largest key value is moved to the end, and the position of the element is noted, and the next order is only required to compare to this location until all el
This paper implements eight commonly used sorting algorithms: Insert sort, bubble sort, select Sort, hill sort, quick sort, merge sort, heap sort and lst cardinal order.
First, the algorithm implementation file Sort.h, the code is as follows:
* * Implements eight common sorting algorithms: Insert sort, bubble sort, select sort, Hill sort * and quick sort, merge sort, heap sort and lst cardinal sort *
Let's take a look at some of the sorting methods commonly used in web effects, we mainly include the bubble Insert Hill sorting method, mainly for array operations.
----------some sort algorithms
//JS sorts using sort
Systemsort:function (Array) {
Return Array.Sort (function (A, b) {
return a-b;
});
},
Bubble sort
Bubblesort:function (Array) {
var i = 0, Len = array.length,
J,
1, with the third variable value exchange
int a = 1;int b = 2;int C = A;A = b;b = C;2. Exchange with addition and subtraction
A = a + B;b = a-b;A = A-b;OrA = A-b;b = A + B;A = b-a;3, in different or (XOR) method Exchange
A = a ^ b;b = a ^ b;A = a ^ B; codeproject on an article
The code is as follows
Copy Code
public enum Echangetype{Pre-and post-value exchange with third-party variable TempThridvar,Using A=a+b;b=a-b;a=a-b calculation method to Exchange before and
And in some scenes, the queue is indeed like a surprise, can bring good results, such as the use of timer, can simulate the time difference effect
Copy Code code as follows:
function Createdq () {
var dq = [], size = 0;
return {
Setdq:function (queue) {
dq = queue;
size = Queue.length;
},
Queue:function (FN) {
Size + +;
Dq.push (FN);
},
Dqueue:function () {
Size--;
return Dq.shift ();
},
Run:function (FN) {
var me = this, timer;
Timer = setinterv
__construct ($name, $age)
{
$this->age = $age;
$this->name = $name;
}
}
We can use another function Usort to specify the sort by age:
Usort ($arr, function ($a, $b) {
if ($a->age = = $b->age) {return
0;
}
Return $a->age > $b->age? 1:-1;
});
2, bubble sort
N numbers to sort, outer loop n-1, inner loop n-1-i, compare J and j+1, and swap
$arr = [3,1,7,9,5,4];
$n = count ($arr);
For ($i =0 $i
JS Common bubble sort, quick sort, insert sort code sharing
4.2.1 Bubble Sort Algorithm Introduction parsing: Compare adjacent two elements, if the previous one is larger than the latter, swap position.
In the first round, the last element should be the largest one.
Follow the steps one method to compare the adjacent two elements, this time because the last element is already the largest, so the last ele
Brief introductionThe bubble algorithm is a basic sort algorithm that repeats the comparison of the two adjacent elements in the array. If one element is larger (smaller) than the other, then the position of the two elements is exchanged. Repeat this comparison until the last element. This comparison will repeat the n-1, each trip to compare N-j times, J is already sorted the number of elements. Each comparison is able to find the largest or smallest
1, principle: compare Array[index] and array[index+1 from the first position of the array, and swap array[if ARRAY[INDEX] is greater than array[index+1] Index] and array[index+1] position, stop to array end; starts at the first position of the array, repeats the action above, and stops at the end of the array length minus one position; The starts at the first position of the array, repeats the action above, and stops at the end of the array length minus two positions; ..... 2, time complex
Select sortselection sorting is a simple and intuitive sort algorithm whose core idea is to traverse an array, find the smallest element in a sequence that has never been sorted, and place it at the end of the sorted sequence.
Complexity of Time: O (n^2)
Stability: Unstable
* * @brief selection Sort
*
/void Selection_sort (int a[], int n)
{
int i, J, Min, tmp;
for (i = 0; i
Direct Insert SortDirect insertion Ordering is a relatively easy to understand sort algori
Package sort;
*
* Bubble Sort:
* *
principle: Traversal, compare the adjacent two number, each traversal, the largest number of the * * * * * */Public
class Bubblesort {public
final void Bubble (int [] arr)/bubbling method, plus final is to prevent being modified
{for
(int x=0;x
("A 是起始杆,C 是辅助杆,B 是目的杆。\n\n"); hanoi(init, 'A', 'C' , 'B'); printf("\nCount = %d", count); return 0; }
By this wind, I'll write the algorithm for sorting, I just remember bubble and quick sort, now write a bubble sort bar:
#include void show (int *p) { int i=0; for (i=0 ;i { printf("%3d ", p[i]); } printf("\n"); } int main(int argc, char *argv[]) { int p[] = {8, 9, 4, 5, 1, 7, 6, 0}; int i = 0; int j = 0
Asp.net| Source Code | validation Controls | bubbles
[Use:]This procedure can improve the display effect of ASP.net's validation control, with a more user-friendly bubble hint to replace the original boring interface hint, and with the "Off prompt" function, effectively resolved an input box with multiple validation controls, display error message information is not in the same place of defects, It also effectively solves the defect that the validatio
In this quick text effect tutorial, we'll create an easy-to-use layer style that quickly converts plain text to bubble style fonts.
In this quick text effect tutorial, we'll create an easy-to-use layer style that quickly converts plain text to bubble style fonts.
This tutorial will teach you how to create text effects as shown in the following illustration.Before you start, you may want to find a suitable
Tutu7.10 bubble dragon puzzle game 1 wants to play the bubble dragon puzzle game under Ubuntu7.10. The bubble dragon Game transplanted from the arcade has always been liked by many friends, especially girls. The screen is cute, and the music is also beautiful. It is suitable for playing with your girlfriend. Come with me. Open the terminal, enter sudoapt-getinsta
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.