To take part in discussions on talkSFU, please apply for membership (SFU email id required).
cmpt 120 help!
oh dear, ok so I'm having a lot of problems with Python programming. it's just not for me...but i'm trying my best!!
one question on my assignment is to create a recursive function that sorts the list from start to end.
this is the pseudocode that the prof sent to help out...
and this is what i have, which doesn't actually work
anyone have knowledge of Python?? any help is appreciated!!
one question on my assignment is to create a recursive function that sorts the list from start to end.
this is the pseudocode that the prof sent to help out...
def selection_sort(lst, start, end):
if start >= end:
return
else:
swap smallest element from lst[start:end+1] into lst[start]
selection_sort(lst, start+1, end)
return
and this is what i have, which doesn't actually work
def selection_sort(lst, start, end):
\"\"\"
sort the list in-place
>>> selection_sort([4, 6, 2, 3, 1], 1, 5)
[1,2,3,4,6]
\"\"\"
if start >= end:
return 0
else: #if start <= end
for i in range(start-1, end+1):
#start finding the values that are less the first number in list
if lst[i] < lst[0]:
lst[0], lst[i] = lst[i] = lst[0]
#find the smallest value and put it at the front
elif lst[i-1] < lst[0]:
lst[0], lst[i-1] = lst[i-1], lst[0]
start = i
lst[start] = lst[i]
#find the largest value and put it at the end of the list
elif lst[i] > lst[end+1]:
selection_sort(lst, start+1, end)
lst[i], lst[end+1] = lst[end+1], lst[i]
#print lst[end-1]
print selection_sort([4,6,2,3,1], 1, 3)
anyone have knowledge of Python?? any help is appreciated!!
Comments
man, this course is killing me. my brain just isn't wired to think like a programmer.
whoa. i was planning to take CMPT 120 next semester.
looks killer. ......
i don't have ANY knowledge of programming what so ever...
think i'll be screwed :confused: :sad:
I've heard OK things about Cukierman though.
im just not spending nearly enough time on this class...
it's not a prerequisite for me, it was just out of interest and curiosity.
The slow way:
You have your robot walk along the walls in a clockwise direction, if it hits an obstacle have it take one step to the left. After every step see if the robot can see it and go to it, otherwise take another step.
The fast way:
Have your robot take a step in a random direction, eventually you will find your coin.
http://www.google.ca/search?q=python+selection+sort
You can probably find the answer to all your first year programming questions on Google. Although, I wouldn't recommend it for obvious reasons. A prof that hates object-oriented programming? He shouldn't be teaching programming then. Unless he's talking about pure OOP.
JayDub, your first algorithm doesn't sound like it'd work. At least not without a few more conditions.
Then again I never did 120, I skipped right to 126.
Phil