Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Python-Bubble Sort will not work..Please help.?

Ive bee trying for the last two days to get this problem. Every time i do it the wind speeds print out as i enter them. The bubble sort does not work.

Please give me tips hints, if you could work it out completely that be brilliant too..

Write a Python program that reads in the names of several airports and the wind-speeds at each one. It must then sort them according to wind-speed (highest first), and print out the sorted data.

You must not use Python’s built-in sort function, but write your own code based on the bubble sort code that we have examined in lectures.

Note that you can use two parallel lists, one to store the airport names and one to store the wind-speeds. As we noted in recent lectures, it is important when sorting parallel lists to make the same changes to both lists, in order to keep the names correctly associated with the wind-speeds.

Test your code on a set of at least 5 airports

1 Answer

Relevance
  • 1 decade ago
    Favorite Answer

    You should use a dictionary data structure for this. An associative array will also do.

    function Bubble Sort (list)

    ->for i=0 to len(list) - 1

    --->for j=0 to len(list) - i - 1

    ----->if list[j] > list[j + 1]

    -------->swap

    ----->end if

    --->end for

    ->end for

    end function

Still have questions? Get your answers by asking now.