bubble-sort

why these 2 sorting is opposite in order

why these 2 sorting is opposite in order Question: I am implementing bubble sort in Python and used range for indexing the array: """ program to implement bubble sort """ a = [9,1,5,3,7,4,2,6,8] for i in range(len(a)): for j in range(i+1, len(a)): if a[i] > a[j]: a[i], a[j] = a[j], a[i] print(a) I got the …

Total answers: 2

random generating numbers in Bubble Sort

random generating numbers in Bubble Sort Question: Here is my question I would like to not use numbers that I use but rather that I can put in random numbers ranging from 0 to 50 and then the list can use bubble method to sort it but I can understand how I can use the …

Total answers: 1

Bubble sort first four pairs of a list

Bubble sort first four pairs of a list Question: How do I use the bubble sort but implement it in such a way it only sorts first 4 pairs of a list? [3, 5, 7, 2, 7, 9, 3, 4, 5, 8] def bubbleSort(arr): n = len(arr) for i in range(n): for j in range(0, …

Total answers: 2

Appending Array into different array N times (python)

Appending Array into different array N times (python) Question: For an assignment where we have to reverse bubble sort. After each movement of this sort we must store the array into a different array known as. The problem being is that the with each movement in Array A it automatically changes the array in the …

Total answers: 1

How exactly does the loop within a bubble sort algorithm work? (Python 3)

How exactly does the loop within a bubble sort algorithm work? (Python 3) Question: Example code: def bubble_sort(my_list): n = len(my_list) for i in range(n): for j in range(0, n – 1 – i): if my_list[j] > my_list[j + 1]: my_list[j], my_list[j + 1] = my_list[j + 1], my_list[j] my_list = [94, 17, 5, 28, …

Total answers: 1

Bubble Sort using a while loop in Python

Bubble Sort using a while loop in Python Question: I’ve been set a bubble sort for homework, and I’ve been trying to use a while loop. I know that it’s possible with a for loop, but I don’t really understand them and I’d like to write something that I understand. unsorted = True numbers = …

Total answers: 5

How to ask for an input and bubble sort that input?

How to ask for an input and bubble sort that input? Question: It’s my first time in coding in Python, I have created a code that bubbles sort a given list. This is my code: def bubbleSort(alist): for passnum in range(len(alist)-1,0,-1): for i in range(passnum): if alist[i]>alist[i+1]: temp = alist[i] alist[i] = alist[i+1] alist[i+1] = …

Total answers: 2

Why is Bubble Sort implementation looping forever?

Why is Bubble Sort implementation looping forever? Question: In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them. This is my attempt in Python: mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = …

Total answers: 29