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.
Address Source Text http://blog.csdn.net/hijiankang/article/details/9207735Note: This is illustrated by the example of the increment sequenceFirst, bubble sort1, principle: Starting from the first position of the array 22 compare Array[index] and array[index+1], if ARRAY[INDEX] greater than array[index+1] then Exchange Array[index] and array[index+1] Position, ending to the end of the array;Starting from the first position of the array, repeat the abo
Recently looking at data structure and algorithm analysis, want to write a note to record, first from the basic bubble, select, insert Start.
Note: This is illustrated by the example of the increment sequence
First, bubble sort
1, principle: Starting from the first position of the array 22 compare Array[index] and array[index+1], if ARRAY[INDEX] greater than arra
Simple sorting (after learning to review in time, otherwise like not to learn the same, andSpend more time in the future)Bubble sort: small number upBubble sort (bubblesort) is a repeated visit to the sorted sequence,Compare two elements at a time, if they are in the wrong order, just put them onSwap them over. The work of the sequence of visits is repeated until
; for(intI =0;i){ for(intj = 0;j){ if(arr[j]>arr[j+1]) {temp=Arr[j]; ARR[J]=arr[j+1]; Arr[j+1]=temp; }}} System.out.println (Arrays.tostring (arr)); }}Performance analysis and algorithm optimization for bubble sequencing (Outer loop optimization) issues:Some bubbles after the first round of exchange is already orderly, such as: 2 1 3 4. The more data you have, the slower it is, and it's very unsuitable for big data sorti
bubbleSort (alist) alist = [54,26, 93,17, 77,31, 44,55, 20] print selectionSort (alist)
If you are interested, you can test the examples in this article. I believe there will be new gains.
Select sorting, fast sorting, Bubble sorting, heap sorting, insert sorting, and the running speed of the basic sorting program.
It depends on time complexity.O (n ^ 2), O (n ^ 2), O (n ^ 2), O (nlog 2 n), O (nlog 2 n ),
In the previous article, we talked about how C # implements bubble sorting. So did you ever think about how to do a bubble sort on any type of data? Here we will answer this question. First we learned that the essence of bubble sort is to rank an array of elements in ascendi
recognized sorting methods (depending on the problem-solving objects ), although the fast sorting method can reach O (n2) in the worst case, the efficiency of the fast sorting method is quite good in most cases. the basic spirit of quick sorting is to find the proper axis in the series, split the series into two parts, and sort the series on the left and right respectively, it is the choice of the axis th
Bubble sort
Bubble sorting is inefficient, but the algorithm is very simple to implement, so it is suitable as an entry algorithm for research sequencing.
Basic ideas
To the current not well-sequenced range of all the number, the top-down to the two adjacent to the number of comparison and adjustment, so that the larger number sinking, the smaller number up
Is mainly the comparison exchange of 2 adjacent records1 PackageCom.trfizeng.changesort;2 3 /**4 * @authorTrfizeng Internal Sort Exchange sort-bubble sort (Bubble sort)5 */6 Public classBubblesort {7 Public Static int[] B
for (int i = 0; i This is how the entire sorted block of code is:public static void bubbleSort(int[] a) { int n = a.length; boolean changed; //判断是否已交换 do { changed = false; for (int i = 0; i The maximum value for the For loop is set to N-1 because there is a A[n + 1] in the IF statement, otherwise the array subscript will be out of bounds.Testing phaseThe same test data:publ
It is well known that loops and recursion, in many cases, can be converted to each other.Then, the bubble sort (Bubble sort), as a typical double loop structure, can also be converted to recursive form.However, converting recursion to a loop is beneficial for the program's o
Java Select sort and Bubble sort1.datasorter.javapublic class Datasorter {//Bubble sort method//main idea: Sort by ascending order, array element 22 comparison, large immediately after public static void Bubblesort (int[] a) {for (int i = 1; i 2.
Algorithm-bubble sort and Quick Sort (Object-C)Bubble is the same as recursion. No matter what the level of everyone is, it can basically make up for writing and writing. In fact, quick sorting is mainly about data exchange, which is exchange sorting. However, quick sorting requires an understanding of the idea of gove
a comparison value key, which takes the first value in the list. Let the other values in the list compare them.If it is less than it is placed in the right list,If it is greater than it is placed in the left list.and then recursion. (Not very understanding of recursion.) Only know that the function itself calls itself. )Finally, left, compare value key (need to convert to list type), right is connected together.An error has occurred:Runtimeerror:maximum recursion depth exceeded while calling a
everything is in order? Yes! That being the case, the next sequence will not be done.For code one. Give the optimized code two:void BubbleSort20 (int a[], int n) //left-to-right {if (a n > 1) {int i,j = N-1;bool flag = true;while (flag) {flag = False;for (i = 0; i think again: the furthest position of the next sort to the right (or left) is simply minus one? Can it be more efficient? Some. Record the maximum distance of the interchange element when
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.