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(1)冒泡排序(Bubble Sort) · 常见排序算法 - 看云
最近整理了一些常见的排序算法,资料基本上都来自网上,大部分参考了维基百科,分析了常见算法的原理,并举例分步说明,有的还给出了排序动画演示,但没有涉及算法复杂 ...
- 2冒泡排序- 维基百科,自由的百科全书
- 3algorithm-excercise/bubble_sort.md at master - GitHub
核心:冒泡,持续比较相邻元素,大的挪到后面,因此大的会逐步往后挪,故称之为冒泡。 Bubble Sort. Reference. 冒泡排序- 维基百科,自由的百科全书.
- 4冒泡排序在PTT/Dcard完整相關資訊| 幸福屋-2022年6月
冒泡排序- 维基百科,自由的百科全书冒泡排序(英語:Bubble Sort)又稱為泡式排序,是一種簡單的排序算法。 它重複地走訪過要排序的數列,一次比較兩個元素,如果他們的 ...
- 5臭皮匠排序- 維基百科,自由的百科全書
臭皮匠排序 ... 臭皮匠排序(英語:Stooge Sort)是一種採用分治法的低效排序算法,甚至慢於冒泡排序。在《算法導論》第二版第7章(快速排序)的思考題中被提到,是由Howard ...