COMP225 PRACTICAL EXERCISES WEEK 2
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.
- Implement an iterative search for Tutorial exercise (1), and check that it works on the identified tests.
- 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.
- (*)
struct Node {
item int;
link; *Node;
}
- Implement a function to insert a node at the front of a linked list.
- Implement a function which prints out the nodes in a linked list.
- 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.)
-
- Implement a recursive function to reverse a linked list.
- Implement a recursive function to print out the items of a linked list.
All enquiries to Annabelle McIver