Bubble Sort - 冒泡排序
文章推薦指數: 80 %
Bubble Sort - 冒泡排序 ... 核心:冒泡,持续比较相邻元素,大的挪到后面,因此大的会逐步往后挪,故称之为冒泡。
... 冒泡排序- 维基百科,自由的百科全书 ...
Preface
FAQ
GuidelinesforContributing
PartI-Basics
BasicsDataStructure
String
LinkedList
BinaryTree
HuffmanCompression
Queue
Heap
Stack
Set
Map
Graph
BasicsSorting
BubbleSort
SelectionSort
InsertionSort
MergeSort
QuickSort
HeapSort
BucketSort
CountingSort
RadixSort
BasicsAlgorithm
DivideandConquer
BinarySearch
Math
GreatestCommonDivisor
Prime
Knapsack
Probability
Shuffle
Bitmap
BasicsMisc
BitManipulation
PartII-Coding
String
ImplementstrStr
TwoStringsAreAnagrams
CompareStrings
GroupAnagrams
LongestCommonSubstring
RotateString
ReverseWordsinaString
ValidPalindrome
LongestPalindromicSubstring
SpaceReplacement
WildcardMatching
LengthofLastWord
CountandSay
IntegerArray
RemoveElement
ZeroSumSubarray
SubarraySumK
SubarraySumClosest
RecoverRotatedSortedArray
ProductofArrayExcludeItself
PartitionArray
FirstMissingPositive
2Sum
3Sum
3SumClosest
RemoveDuplicatesfromSortedArray
RemoveDuplicatesfromSortedArrayII
MergeSortedArray
MergeSortedArrayII
Median
PartitionArraybyOddandEven
KthLargestElement
BinarySearch
FirstPositionofTarget
SearchInsertPosition
SearchforaRange
FirstBadVersion
Searcha2DMatrix
Searcha2DMatrixII
FindPeakElement
SearchinRotatedSortedArray
SearchinRotatedSortedArrayII
FindMinimuminRotatedSortedArray
FindMinimuminRotatedSortedArrayII
MedianoftwoSortedArrays
Sqrtx
WoodCut
MathandBitManipulation
SingleNumber
SingleNumberII
SingleNumberIII
O1CheckPowerof2
ConvertIntegerAtoIntegerB
FactorialTrailingZeroes
UniqueBinarySearchTrees
UpdateBits
FastPower
HashFunction
HappyNumber
Count1inBinary
Fibonacci
AplusBProblem
PrintNumbersbyRecursion
MajorityNumber
MajorityNumberII
MajorityNumberIII
DigitCounts
UglyNumber
PlusOne
PalindromeNumber
TaskScheduler
LinkedList
RemoveDuplicatesfromSortedList
RemoveDuplicatesfromSortedListII
RemoveDuplicatesfromUnsortedList
PartitionList
AddTwoNumbers
TwoListsSumAdvanced
RemoveNthNodeFromEndofList
LinkedListCycle
LinkedListCycleII
ReverseLinkedList
ReverseLinkedListII
MergeTwoSortedLists
MergekSortedLists
ReorderList
CopyListwithRandomPointer
SortList
InsertionSortList
PalindromeLinkedList
LRUCache
RotateList
SwapNodesinPairs
RemoveLinkedListElements
BinaryTree
BinaryTreePreorderTraversal
BinaryTreeInorderTraversal
BinaryTreePostorderTraversal
BinaryTreeLevelOrderTraversal
BinaryTreeLevelOrderTraversalII
MaximumDepthofBinaryTree
BalancedBinaryTree
BinaryTreeMaximumPathSum
LowestCommonAncestor
InvertBinaryTree
DiameterofaBinaryTree
ConstructBinaryTreefromPreorderandInorderTraversal
ConstructBinaryTreefromInorderandPostorderTraversal
Subtree
BinaryTreeZigzagLevelOrderTraversal
BinaryTreeSerialization
BinarySearchTree
InsertNodeinaBinarySearchTree
MinimumAbsoluteDifferenceinBST
ValidateBinarySearchTree
SearchRangeinBinarySearchTree
ConvertSortedArraytoBinarySearchTree
ConvertSortedListtoBinarySearchTree
BinarySearchTreeIterator
ExhaustiveSearch
Subsets
UniqueSubsets
Permutations
UniquePermutations
NextPermutation
PreviousPermuation
PermutationIndex
PermutationIndexII
PermutationSequence
UniqueBinarySearchTreesII
PalindromePartitioning
Combinations
CombinationSum
CombinationSumII
MinimumDepthofBinaryTree
WordSearch
DynamicProgramming
Triangle
Backpack
BackpackII
MinimumPathSum
UniquePaths
UniquePathsII
ClimbingStairs
JumpGame
WordBreak
LongestIncreasingSubsequence
PalindromePartitioningII
LongestCommonSubsequence
EditDistance
JumpGameII
BestTimetoBuyandSellStock
BestTimetoBuyandSellStockII
BestTimetoBuyandSellStockIII
BestTimetoBuyandSellStockIV
DistinctSubsequences
InterleavingString
MaximumSubarray
MaximumSubarrayII
LongestIncreasingContinuoussubsequence
LongestIncreasingContinuoussubsequenceII
MaximalSquare
Graph
FindtheConnectedComponentintheUndirectedGraph
RouteBetweenTwoNodesinGraph
TopologicalSorting
WordLadder
BipartialGraphPartI
DataStructure
ImplementQueuebyTwoStacks
MinStack
SlidingWindowMaximum
LongestWords
Heapify
BigData
TopKFrequentWords(MapReduce)
TopKFrequentWords
TopKFrequentWordsII
KClosestPoints
TopkLargestNumbers
TopkLargestNumbersII
ProblemMisc
NutsandBoltsProblem
StringtoInteger
InsertInterval
MergeIntervals
MinimumSubarray
MatrixZigzagTraversal
ValidSudoku
AddBinary
ReverseInteger
GrayCode
FindtheMissingNumber
MinimumWindowSubstring
ContinuousSubarraySum
ContinuousSubarraySumII
LongestConsecutiveSequence
PartIII-Contest
GoogleAPAC
APAC2015RoundB
ProblemA.PasswordAttacker
APAC2016RoundD
ProblemA.DynamicGrid
Microsoft
Microsoft2015April
ProblemA.MagicBox
ProblemB.ProfessorQ'sSoftware
ProblemC.IslandsTravel
ProblemD.Recruitment
Microsoft2015April2
ProblemA.LuckySubstrings
ProblemB.NumericKeypad
ProblemC.SpringOuting
Microsoft2015September2
ProblemA.FarthestPoint
AppendixIInterviewandResume
Interview
Resume
Tags
本书使用GitBook发布
BubbleSort
BubbleSort-冒泡排序
Implementation
Python
Java
复杂度分析
Reference
核心:冒泡,持续比较相邻元素,大的挪到后面,因此大的会逐步往后挪,故称之为冒泡。
Implementation
Python
#!/usr/bin/envpython
defbubbleSort(alist):
foriinxrange(len(alist)):
print(alist)
forjinxrange(1,len(alist)-i):
ifalist[j-1]>alist[j]:
alist[j-1],alist[j]=alist[j],alist[j-1]
returnalist
unsorted_list=[6,5,3,1,8,7,2,4]
print(bubbleSort(unsorted_list))
Java
publicclassSort{
publicstaticvoidmain(String[]args){
int[]unsortedArray=newint[]{6,5,3,1,8,7,2,4};
bubbleSort(unsortedArray);
System.out.println("Aftersort:");
for(intitem:unsortedArray){
System.out.print(item+"");
}
}
publicstaticvoidbubbleSort(int[]nums){
intlen=nums.length;
for(inti=0;i
延伸文章資訊
- 1臭皮匠排序- 維基百科,自由的百科全書
臭皮匠排序 ... 臭皮匠排序(英語:Stooge Sort)是一種採用分治法的低效排序算法,甚至慢於冒泡排序。在《算法導論》第二版第7章(快速排序)的思考題中被提到,是由Howard ...
- 2侏儒排序- 维基百科,自由的百科全书
此后Dick Grune(英语:Dick Grune)也描述了这一算法,称其为“侏儒排序”。此算法类似于插入排序,但是移动元素到它该去的位置是通过一系列类似冒泡排序的移动实现的。从 ...
- 3时间复杂度转载自维基百科3_alittlewhitea的博客
维基百科,自由的百科全书. 在计算机科学中,算法的时间复杂度是一个函数,它 ... 冒泡排序、插入排序 ... 例如,矩阵链排序可以通过一个PRAM模型.
- 4排序简介 - OI Wiki
基数排序、计数排序、插入排序、冒泡排序、归并排序是稳定排序。 选择排序、堆排序、快速排序 ... 外部链接¶. 排序算法- 维基百科,自由的百科全书 ...
- 5冒泡排序在PTT/Dcard完整相關資訊| 幸福屋-2022年6月
冒泡排序- 维基百科,自由的百科全书冒泡排序(英語:Bubble Sort)又稱為泡式排序,是一種簡單的排序算法。 它重複地走訪過要排序的數列,一次比較兩個元素,如果他們的 ...