tutorial11a

tutorial11a - CSC2100B CSC2100B DataStructures Tutorial11...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
CSC 2100B CSC 2100B Data Structures Data Structures Tutorial 11 Tutorial 11 10 th  April 2007
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Assignment 2 Assignment 2 Question 1: quite well done. Question 2: Well done. Question 3a (double hashing): few people  got it completely correct. Question 3b (ProcessTrans.java): fine
Background image of page 2
3 Question 1B Question 1B The function not_in that accepts an int argument and a List argument, and  returns a boolean value: true if the int argument is not in the List  argument, or false otherwise.  For examples: not_in(2, [3,4,8,2,4]) = false not_in(2, []) = true not_in(4, [3,5]) = true boolean not_in(int x, List L1) { if (L1.isEmpty()) return true; if (L1.head() == x) return false; else return (not_in(x, L1.tail())); }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Question 1C Question 1C The function alldiff that accepts a List argument and returns  a boolean value true: if all elements in the list are  different, or false otherwise.  For examples: alldiff([4,3,4,2,1]) = false alldiff([]) = true alldiff([0,1]) = true boolean alldiff(List L1) { if (L1.isEmpty()) return true; return (not_in(L1.head(), L1.tail()) && alldiff(L1.tail()); }
Background image of page 4
Question 1E Question 1E The function listEqual that accepts two List arguments, and returns  a boolean value true if the two lists are equal, or false  otherwise.  For examples: listEqual([], []) = true listEqual([], [3,2,3]) = false listEqual([1,2,2,1], []) = false listEqual([1,2,3], [1,2,4]) = false listEqual([8,9], [8,9]) = true boolean listEqual(List L1, List L2) { if (L1.isEmpty() && L2.isEmpty()) return true;
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 40

tutorial11a - CSC2100B CSC2100B DataStructures Tutorial11...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online