Contents

  1. descendSort.py

descendSort.py

# Demonstrate passing lists to functions
# CSCI111

# this function tests the descend sort function
def main():
    # test descendSort3Nums
    list = [1,2,3]
    descendSort3Nums(list)
    print list

    list = [0, 5, -3]
    descendSort3Nums(list)
    print list
    
    list = [7,4,1]
    descendSort3Nums(list)
    print list

# input: a list containing three numbers
# sorts the list in descending order
# Note: does not return anything, no output
def descendSort3Nums(list3):
    if list3[1] > list3[0]:
        # swap 'em
        tmp = list3[0]
        list3[0] = list3[1]
        list3[1] = tmp

    if list3[2] > list3[1]:
        # swap 'em
        tmp = list3[1]
        list3[1] = list3[2]
        list3[2] = tmp
    
    if list3[1] > list3[0]:
        # swap 'em
        tmp = list3[0]
        list3[0] = list3[1]
        list3[1] = tmp
        
main()

Generated by GNU enscript 1.6.4.