Bubble sort and its implementation
2010-07-23 07:27
363 查看
Bubble sort is quite like the insertion sort. In the insertion sort, the left part of the array is always ordered, which is the same in Bubble sort.
In bubble sort, the adjacent elements are compared and swaped if the higher element is larger than the lower element, and the compare-and-swap procedure will stop when the bubble sort reach the upper bound of the unsorted array.
In bubble sort, the adjacent elements are compared and swaped if the higher element is larger than the lower element, and the compare-and-swap procedure will stop when the bubble sort reach the upper bound of the unsorted array.
class BubbleSortAlgorithm { public void BubbleSort(int[] array) { bool exchanged = false; // to check whether the array is sorted. for (int i = 1; i < array.Length; i++) { for (int j = array.Length - 1; j >= i; j--) { if (array[j] < array[j - 1]) { exchanged = true; int temp = array[j]; array[j] = array[j - 1]; array[j - 1] = temp; } } if (exchanged == false) { return; } } } }
相关文章推荐
- Shell sort and its implementation
- Selection sort and its implementation
- The implementation of anonymous methods in C# and its consequences
- Business Process Implementation for IT Professionals and Managers
- bubble sort and heap sort and quick sort
- 冒泡排序设标志避免重复:Sort:Bubble Sort using tag and Xor operation
- The bubble sort and Binary search
- IT Compliance and Controls: Best Practices for Implementation
- Bubble, Insertion, Selection, Quick and Heap Sort
- JQuery DOM HighLighter (it's a basic "Inspect element" simple implementation to mimic what webkit inspector and firebug do)
- Greedy and its implementation with python
- [CC-SEABUB]Sereja and Bubble Sort
- BubbleSort and SelectSort
- Merge Sort and apply it to an interview question
- The implementation of anonymous methods in C# and its consequences
- scala sortBy and sortWith
- TIME_WAIT and its design implications for protocols and scalable client server systems
- insertion mergesort bubble sort 复习 python
- Double-checked Locking (DCL) and how to fix it
- install eigen in ubuntu and use it in qt