## Lecture 16 -

As usual, create a directory to hold today's activities:

$mkdir ~/cs170/labs/lab16$ cd ~/cs170/labs/lab16


# POP QUIZ

I was never a fan of pop quizzes as a student. However, I have come to understand the purpose of them; Students need to make sure they are keeping up with the material on a daily basis. So today, we are going to have a timed pop quiz. You have 10 minutes to answer these questions: here

Test Review Activities
Test Review

In addition to the written portion of the test, there will be a coding portion. This will be done on the computers. For practice, attempt the following exercises, alone:

1. Write a function called is_palindrome(a_string), which takes a single string as a parameter. Your function should return True if the parameter string is a palindrome.

A string is a palindrome if its first and last letters are the same, and the string without the first and last letters is a palindrome. Notice that a string of length <= 1 is always a palindrome.

2. Write a recursive function called double_list(a_list), which takes a list of elements as a parameter. Your function should return a new list, where every item in the parameter list appears twice in the resulting list.

      >>> a_list = [1, 2, 3]
>>> print(double_list(a_list))
[1, 1, 2, 2, 3, 3]

3. Write a function called shaker(a_list), which takes a list of comparable elements. Your function should not return anything. Instead, it should sort a_list in place using the Cocktail Shaker sort algorithm.

Cocktail Shaker sort is very similar to bubble sort. It only compares elements that are side by side, and swaps them if they are out of order. In Bubble sort, we always started from the beginning of the list, and worked our way to the end. In Cocktail Shaker sort, we first start at the beginning and work our way to the end. Afterwards, we will work from the end of the list back to the beginning. We will repeat these two procedures until the list is in sorted order.