0

Hi guys,

I got this from my teacher and im really confused. could anyone point me in the right direction?

Thanks

What does it do?

This time I'm looking for an overall summary, in one sentence, with the word "by" in the middle:

"This function ..........., by ................ ."

This function takes a list of numbers as an argument, and returns a list of numbers.
To help you figure it out, cut out 5 or 6 pieces of paper, write some numbers on them, put them on a table, and run the algorithm yourself.

define MyFunction (list):
    for OuterForLoopCounter in 1 to listlength-1:
        for InnerForLoopCounter in 1 to listlength-1:
            if list[InnerForLoopCounter] is greater than list[InnerForLoopCounter+1]:
                swap list[item] and list[item+1]
    return (list)

Edited by pyTony: fixed the code formating, use the code button more selectively

3
Contributors
3
Replies
6
Views
4 Years
Discussion Span
Last Post by Lucaci Andrew
1

Look articles on sorting algorithm based on swapping adjacent items.

Edited by pyTony

1

Let me give you a head start:

def myfunc(l):
    for i in range (1, len(l)-1):
        for j in range (1, len(l)-1):

for

define MyFunction (list):
    for OuterForLoopCounter in 1 to listlength-1:
        for InnerForLoopCounter in 1 to listlength-1:

now, how about implementing the rest:

 if list[InnerForLoopCounter] is greater than list[InnerForLoopCounter+1]:
                swap list[item] and list[item+1]
    return (list)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.