NUIMCrest CS211 - Algorithms and Data Structures II
Department of Computer Science, NUIM
Laboratory Sheet 6

For week beginning Monday 28 February 2000
From: T. Naughton

In this laboratory you will become more familiar with working with linked list data structures. There are two programs to write, Problems 6.1 and 6.2. Show a demonstrator a working solution to each problem to get a credit. When finished, start on the list at the end of this lab sheet.

Back to CS211 home


Notices:

  • Please read this email that you should have received last Friday.

  • There will be no labs or lectures for the week beginning 6 Mar 2000 (mid term break).

  • A tutorial in basic programming (Tutorial 3), at the level of course CS100, will be held during the next lecture slot (2 Mar 2000). Have a look at the list of problems for this tutorial and attend if you feel you need to.
    Further tutorial times may be agreed with the tutor(s) at this session (scheduled during mid-term break, if there is demand). Details will be posted on the Tutorials Page as soon as confirmed.

  • After the mid-term break (week beginning 13 Mar 2000) there will be a lab exam on linked list data structures. No computers, books, or notes will be permitted. Given that you will have a week to prepare, plenty of sample solutions at this www site, a list of possible questions at the end of this lab sheet, and a tutor (or tutors) at your disposal, I expect everyone to perform well at this exam.


    In Laboratory 5 you had to implement a linked list application using classes. Here are the problems again.

    Here is a solution to Problem 5.1, with a test routine coded in main(). Make sure you understand all of this program. Ask your demonstrators to explain it if you have any difficulties (remember, drawing the linked list pictures will help you!). I have outlined how to solve Problem 5.2 in lectures.

    Here are this week's problems. Once again, those students who do some work during the week will find they have a head start.

    Problem 6.1 Same as Problem 5.2. A second chance to get a credit for this problem.

    Problem 6.2 A class to maintain an ordered linked list of integers is required. Integers are to be sorted in ascending order. Call your class OrdIntList. The following methods should be supported by your class:

  • OrdIntList::Add // Add an integer to the list at an appropriate position
  • OrdIntList::PrintList // Print out the contents of the list
  • OrdIntList::Contains // Return true/false if an integer is in the list
    This problem is very similar to previous problems except, as explained in the last lecture, your Add() method must determine which position in the list to add the new node.

    There is no need for any user interaction. Use main() to test your program. An example of one such main() is shown below (text version here).

    As soon as you are finished a problem, please show your solution to a demonstrator and they will mark you down for a credit (one credit per problem). When you are finished both problems, try to write methods for the following tasks. Good luck!

    Linked list functionality that may be required in the future:


    Information for Demonstrators:

    When checking Problem 6.1, try all three possible delete cases (deleting from the front of the list, from the middle of the list, from the end of the list).


    End of Lab Sheet