Due Date: midnight, Friday, 14 December.
This assignment focuses on basic searching and sorting from Chapter 13.
Submit the following programs via Blackboard:
function insertionSort(array A) for i from 1 to length[A]-1 do value := A[i] j := i-1 while j >= 0 and A[j] > value do A[j+1] := A[j] j := j-1 done A[j+1] := value done
(pseudocode from Rosetta Code )
Write a main program that demonstrates that your insertion sort function works.
(Hint: this does not have to be a graphics program, printing the list before and after is fine.)
The following program uses recursion to draw a square spiral:
#From http://interactivepython.org/courselib/static/pythonds/Recursion/graphical.html import turtle #This function draws a line, turns right, and calls itself # to draw a shorter line: def drawSpiral(t,lineLength): if lineLength > 0: t.forward(lineLength) t.right(90) drawSpiral(t, lineLength-5) def main(): #Set up a turtle: myTurtle = turtle.Turtle() #Set up a graphics window: myWin = turtle.Screen() #Call the function that will draw a spiral drawSpiral(myTurtle,150) #After mouse click, close window myWin.exitonclick() main()
Modify the program so that it draws a triangular spiral.
(Hint: Think about the difference about between a square and a triangle. You only need to modify one line of code.)
For more information on using Blackboard, see the first lab.