Jun-30-2018, 03:23 AM
You're not passing lists to switch, you are passing the values in the list. So the actual exchange isn't involving the lists.
Is this homework? Because this is just a really bad idea all around. But assuming it's homework, have you covered tuple assignment?
Note that your loop is going to mess it all up. You are looping through all of the indexes. So say you start the loop for x == 5. The first y value will be 0, and you will be comparing data[5] to data[0], which is way before data[5]. You need to look into sorting algorithms. This kind of looks like bubble sort, but there you just check adjacent indexes, and you check them until no further swaps are needed.
Is this homework? Because this is just a really bad idea all around. But assuming it's homework, have you covered tuple assignment?
data[x], data[y] = data[y], data[x]That will handle what the swap function does. Otherwise you will need to either do the swap stuff in the sortList function, or pass three things to the swap function: The whole list and the two indexes.
Note that your loop is going to mess it all up. You are looping through all of the indexes. So say you start the loop for x == 5. The first y value will be 0, and you will be comparing data[5] to data[0], which is way before data[5]. You need to look into sorting algorithms. This kind of looks like bubble sort, but there you just check adjacent indexes, and you check them until no further swaps are needed.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures