About 38,600 results
Open links in new tab
  1. sorting - Bubble sort descending list in Python - Stack Overflow

    May 13, 2017 · How can I arrange a list, with bubble sort, but in descending order? I searched in other topics, but I couldn't find an answer. This is my working implementation of Bubblesort code:

  2. Bubble Sort in Descending Order in Python - Source Code

    bubble_sort_descending(): This function sorts the list in descending order using the Bubble Sort algorithm. It uses nested loops: the outer loop guarantees that we iterate through the list enough times to sort it, while the inner loop compares and swaps elements as necessary.

  3. Bubble Sort - Python - GeeksforGeeks

    Feb 21, 2025 · Bubble Sort algorithm, sorts an array by repeatedly comparing adjacent elements and swapping them if they are in the wrong order. The algorithm iterates through the array multiple times, with each pass pushing the largest unsorted element to its …

  4. Bubble Sort help in python - ascending & descending order

    Jan 16, 2014 · >>> xs = [1, 2, 9, 4, 0] >>> bubble_sort(xs, asc=True) [0, 1, 2, 4, 9] >>> bubble_sort(xs, asc=False) [9, 4, 2, 1, 0] So in effect swapping your logical operator < to > reverses the sorting order.

  5. python - Using Bubble Sort, how can I use the second element …

    Oct 7, 2021 · I was trying to use bubble sort in sorting a linked list in descending order. My code prints out a list in alphabetical order instead. I wanted to print out the second element and sort it from highest to lowest value instead of alphabetical order. What am I missing here? If someone can point this out, I would entirely be grateful thanks.

  6. Python program for bubble sort [3 methods] - Python Guides

    Oct 12, 2023 · Bubble sort is a simple sorting algorithm that repeatedly steps through the Python list of elements to be sorted, compares adjacent elements, and swaps them if they are in the wrong order. This process is repeated until the entire Python list is sorted.

  7. Python Bubble Sort - ZetCode

    Mar 8, 2025 · In this article, we explain the Bubble Sort algorithm in Python. We cover sorting numeric and textual data in ascending and descending order. We also compare Bubble Sort with Quick Sort and perform a benchmark. An algorithm is a step-by-step procedure to solve a problem or perform a computation.

  8. Bubble Sort Program in Python - Python Examples

    To sort in descending order, you just need to reverse the list after sorting. nlist[j], nlist[j + 1] = nlist[j + 1], nlist[j] #input list . The outer loop runs through the entire list and progressively moves towards the start of the list after each pass.

  9. Bubble Sort (With Code in Python/C++/Java/C) - Programiz

    # Bubble sort in Python def bubbleSort(array): # loop to access each array element for i in range(len(array)): # loop to compare array elements for j in range(0, len(array) - i - 1): # compare two adjacent elements # change > to < to sort in descending order if array[j] > array[j + 1]: # swapping elements if elements # are not in the intended ...

  10. Bubble Sort – Algorithm in Java, C++, Python with Example Code

    Sep 29, 2022 · Bubble sort is a type of sorting algorithm you can use to arrange a set of values in ascending order. If you want, you can also implement bubble sort to sort the values in descending order. A real-world example of a bubble sort algorithm is how the contact list on your phone is sorted in alphabetical order.

Refresh