Alibabacloud.com offers a wide variety of articles about test cases for bubble sort, easily find your test cases for bubble sort information here online.
C language sorting algorithm of the simple exchange of sorting, direct selection of sorting, bubble sort, the recent test to use, there are many examples on the Internet, I think it is to write their own to understand some.
Simple Exchange Method sorting1 / * Simple Exchange MethodSort2 The position of the two records in the sequence based on the comparison o
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[
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
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
First, the basic ideaBubble sort is a sort of numeric-based exchange, starting with the first element, and comparing it to an element immediately following it, if the current number is larger, then the values of the two are exchanged, then the larger elements move backwards like bubbles. The nth order allows the nth element to go backwards in the past. After a "bubbling operation" such as n-1, the entire se
;i10000; i++) - { -a[i]=10000-i; A } +QuickSort (A,0,9999); the //Bubblesort (a,9999); - /*for (int i=0;i $ { the printf ("%d\n", A[i]); the } */ the return 0; the}The running results show:Bubble sorting and quick sort performance are similar when the amount of data is small, bubbling can sometimes be more expensive, probably because of the reason for the recursive function to go into the stack for a quick run ...But as the amo
faster than bubble sorting.4. SummaryThe above three kinds of sorting, bubbling , selecting , inserting with large o notation all require O (N2) time level. bubbling sorting is not generally selected , although bubbling sort writing is the simplest, but the average performance is not to choose sort and insert sort we
Design 10 or more test cases to complete the functional testing of staple staples(1) using different paper material thickness, using the same specifications staples, to see if the stapler is working properly(2) using different specifications of staples, using the same thickness of paper material, to see if the stapler is working properly(3) Test stapler is used i
sorted out, and does not stop this will be a waste of time complexity. 3 * Analysis: When the large number is constantly moving back, the next time the sorting test again found that the current is already in sequence, then no longer continue to loop directly out4 * The time-saving complexity here is worth it: the number of times for the For loop is reduced: for example {1, 3, 2, 9, 4}5 * After the first bubble
round, the result is false and jumps out without the next round of retrieval - } - returnArray//return Array - } - ///////////End Bubble Sort in}I added a judge in the inside whether the sorting is finished, if the sort has been completed, then immediately end the sort, do not continue to cycle
Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5775Bubble SortTime limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)Total Submission (s): 636 Accepted Submission (s): 378Problem Descriptionp is a permutation of the integers from 1 to N (index starting from 1).Here are the code of Bubble Sort in C + +.for (int i=1;iAfter the sort, th
Bubble SortTime limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)Total submission (s): 591 Accepted Submission (s): 359Problem Descriptionp is a permutation of the integers from 1 to N (index starting from 1).Here are the code of Bubble Sort in C + +.for (int i=1;i for (int j=n,t;j>i;-j) if (P[j-1] > P[j]) t=p[j],p[j]=
assignment operations is related to the input data. In the best case, that is, in the first order, the number of assignments is 0. In the worst-case scenario (worst case), the number of assignments is (n-1) n/2. Assuming that the input data is evenly distributed (or "completely random"), then there are approximately half of the number of exchanges. From the result above, the average condition (average case) can be obtained under the assignment number of 3/2 * (n^2)/2 = 3/4* (n^2).In summary, in
Analysis of complexity of bubble sort time
Bubble Sorting repeatedly visits the series to be sorted and compares two elements at a time. If their order is wrong, they will be exchanged. The work of visiting a sequence is repeated until there is no need for exchange, that is, the sequence has been sorted.The operation of the B
Title Link: HDU 5775Surface:Bubble SortTime limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)Total submission (s): 709 Accepted Submission (s): 418Problem Descriptionp is a permutation of the integers from 1 to N (index starting from 1).Here are the code of Bubble Sort in C + +.for (int i=1;iAfter the sort, the array was in increasing ord
Bubble Sort Algorithm (JAVA)
I. Overview
The day before yesterday, someone asked the next sorting algorithm implementation, so draw time to write a bubble sorting algorithm. The bubble sort algorithm works by starting with the first number, then comparing the current number
comparison ...For example, after the first round of sorting, then in the second round of sorting, the countdown to the first actually did not have to compare, because again the first round of sorting, has been very clear, the last one is the largest.There is a place for optimization here: for (int// a.length-1 marked n-1 wheel for (int i = 0; i // subtract a "j" here, so the number of "corresponding reciprocal positions" is not compared with each other. if // if A[i] is larger than a
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.