COMP225 Practical Exercises

Week 2

Submit an attempt of the starred exercise in a file called "front.cc" via Blackboard before Monday of Week 3. Your practical supervisor will give you feedback and a mark at the practical class in Week 3.

  1. Implement an iterative search for Tutorial exercise (1), and check that it works on the identified tests.

  2. For Question (5) of the Tutorials, copy the program fragments, and adapt them by adding a counter which counts the number of iterations. Try varying the parameter n, and look at how it affects the number of iterations (eg plot a graph). We will investigate such relationships for other more complicated programs later.

  3. (*)
     
                 struct Node {
                   item int;
                   link; *Node;
                 }
          
    1. Implement a function to insert a node at the front of a linked list.
    2. Implement a function which prints out the nodes in a linked list.
    3. Now write a program which tests the above functions, by inserting two items and printing them out. Put your work in a file called front.cc, and make sure it compiles on vesuvius using the command "g++ front.cc". (To run your program use "./a.out" after successful compilation.)

    1. Implement a recursive function to reverse a linked list.
    2. Implement a recursive function to print out the items of a linked list.

    All enquiries to Annabelle McIver