![]() |
CS210 - Algorithms and Data Structures I Department of Computer Science National University of Ireland, Maynooth |
T Naughton, NUIM
Back to CS210 home
Laboratory Sheet 3
Iteration and stepwise refinement (cont.) This lab exam will give you another chance to hone your while loop programming skills.
The near future...
First, make sure you have completed last week's lab. Then tackle the following problems. Once again, use your lab books for all writing. Use of the compiler is not permitted during this lab. Concentrate on pseudocode and REASON about whether your program works or not, rather than letting a dumb computer tell you.
Problem 3.1 Write a function that takes an integer array as a parameter and checks if the array is a palindrome. (A palindrome reads the same backwards as it does forwards -- {1,2,2,1} and {21,2,21} are palindromes, {1,1,2,1} is not.) For the purposes of this assignment, an empty array is also a palindrome.
void Palindrome(int a[]) {
/* This function checks if a[] is a palindrome.
*/
// Your code here
}
Problem 3.2 Write a function that takes an integer array of length n and prints out the array n times, each time starting at a new element and wrapping around to the beginning of the array (if needed) until each element has been printed out. This sample output of the function occurs when the input is the array {0, 5, 10, 12}.
0 5 10 12
5 10 12 0
10 12 0 5
12 0 5 10