ITFN 2313 Mid-Term (Fall 2008)

 

  1. Describe the queue and its operations.  [15 Points]

 

  1. What does the following code accomplish if is called as follows:  testString(s, 0, s.length-1)?  Briefly explain what happens with each line. [15 Points]

 

       public static bool testString(string s, int left, int right)

        {

            if (left >= right)                      

                return true;

            else if (s[left] !=  s[right])        

                return false;

            else                           

                return TestString(s, left + 1, right -1);

            }

 

  1. Describe a recursive function.  What are the two critical elements of a recursive function?  Using the recursive function in problem 2, give examples of these two elements.  [15 Points]

 

  1. Describe the stack data structure and its primary operations.  [15 Points]

 

  1. Describe how the stack would look following these actions:  [10 Points]

              string monthSix = “June”;  string monthFour = “April”;  string monthTen = “October”; string month Five = “May”;

 

stack.push(monthTwo);

stack.push (monthTen);

stack.pop();

stack.push(July);

stack.push(monthFour);

stack.push(month Six);

stack.push(August)

stack.push(monthSix);

stack.pop();

stack.push(January);

 

  1. Write a recursive function that displays the numbers counting up by 2 (0, 2, 4, 6, …) to 100.  Be sure you indicate how it would be invoked to get the desired results.  [15 Points]

 

  1. Describe how this instance of the queue would look following these actions: [10 Points]

int num1=12;  int num2=15;  int num3=32;

 

              queue.Enqueue(num3+num1);

              queue.Enqueue(num3);

              queue.Enqueue(num1);

              queue.Enqueue(num2)

              queue.Dequeue();

              queue.Enqueue(num2+num3);

              queueEnqueue(45);

              queueEnqueue(17);

              queue.Dequeue();

              queue.Dequeue();

 

  1. Describe two ways in which an ArrayList is superior to storing items in array.   [10 Points]
     
  2. Write a snippet of code that asks the user to enter a number.  Then, create an exception handler that responds if the user enters something other than a number.  Hint: Your answer should include a try block and a catch block. (15 Points)