Download presentation
Presentation is loading. Please wait.
Published byGordon Green Modified over 6 years ago
2
PC02 Term 2 Test Recursion and Sorting
3
Many things have been looked at this term
Test Introduction Many things have been looked at this term Recursion Stacks Sorting Algorithms Working with files The following exercises will test your knowledge on some of these areas Feel free to create a main() function to test each of the functions/classes you make
4
For the first part of the test you will need to complete a quiz
You can find it here:
5
Create a static void function called count
Test (1) Create a static void function called count accepts two numbers – currentNumber and limit It should print all numbers from 0 up to limit using recursion (function calling itself) Loops are not allowed! Don’t forger that it needs to stop when currentNumber = limit Call this function from main and use 0, 10 as it’s parameters
6
Test (2) Create a Kitten class that implements Comparable
Compared against other Kittens Has a private integer instance variable – cuteness Assign a value to this instance variable using a constructor (that requires a parameter) Override the compareTo() function, returning -1, 0, or 1 by comparing cuteness of the Kittens 1 if it’s greater, -1 if smaller, 0 if they’re the same
7
In main, create a list with at least 5 kittens with different cuteness
Test (2) In main, create a list with at least 5 kittens with different cuteness Print them to the console Use Collections.sort() and then print again
8
In main, create a linked list
Test (3) In main, create a linked list Use a for loop to fill it with random integers Declare two long variables and call them startTime and endTime Set startTime to System.CurrentTimeMillis(); Then, use “Collections.shuffle(list_name)” to shuffle the list Finally, set endTime to System.CurrentTimeMillis and print the difference to the console
9
Move on to the next slide for some extra exercises
END OF TEST Move on to the next slide for some extra exercises
10
Create a static function in the Kitten class
Test (EXTRA) Using only recursion, create a function (use as many parameters as needed): drawTriangleRecurse Draws a right-angle triangle (with right-angle at bottom-left) onto the console You cannot use for-loops or while-loops to do this You are free to make other functions to accomplish this Create a static function in the Kitten class insertionSort(kittenList) Requires a List of Kittens as the parameter Sorts this List using the Insertion Sort algorithm … Or carry on working on your project!
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.