气泡图 网页可视化_气泡排序可视化

气泡图 网页可视化

What you need:

您需要什么:

1) Unsorted array

1)未排序的数组

2) for loop i - number of loop is based on the number of elements in the array. Each loop of i would reset loop of j to index zero.

2)for循环i-循环数基于数组中元素的数量。 i的每个循环会将j的循环重置为索引零。

3) for loop j - number of loop is based on number of loop i minus - 1 for every loop of j. Why? we are already sure that the last element of each loop is sorted and doesn't needed to be compared in the next loop (hence -1).

3)对于循环j-循环数基于循环数i减去j的每个循环-1。 为什么? 我们已经确定每个循环的最后一个元素已排序,并且不需要在下一个循环中进行比较(因此为-1)。

4) a variable to switch number. you don't need this in Python.

4)切换数字的变量。 您在Python中不需要这个。

Visualization:

可视化:

If you are wondering how i made this, i used Numbers App in my MacBook.

如果您想知道我是怎么做到的,我在MacBook中使用了Numbers App。

用于实现冒泡排序的Python程序 (Python program for implementation of Bubble Sort)

def bubbleSort(arr):
  n = len(arr)

  # Traverse through all array elements 
  for i in range(n): 

	  # Last i elements are already in place 
	  for j in range(0, n-i-1): 
  
  		  # traverse the array from 0 to n-i-1 
		  # Swap if the element found is greater 
		  # than the next element 
		  if arr[j] > arr[j+1] : 
			  arr[j], arr[j+1] = arr[j+1], arr[j]

上面要测试的驱动程序代码 (Driver code to test above)

arr = [64, 34, 25, 12, 22, 11, 90]

bubbleSort(arr)
print ("Sorted array is:")

for i in range(len(arr)):
    print ("%d" %arr[i]),

Source for code: https://www.geeksforgeeks.org/bubble-sort/

代码源: https : //www.geeksforgeeks.org/bubble-sort/

翻译自: https://www.freecodecamp.org/news/cjn-bubble-sort-visualized/

气泡图 网页可视化

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值