CS211 - Algorithms and Data Structures II
Tutorial 6

T Naughton, CS NUIM
Back to CS211 home


This is a tutorial on linked lists.
Problems 6.2, T6.1

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).

    Problem T6.1 There are many ways of printing out a singly-linked list in reverse order. Outline how to solve the problem using each of the following techniques:

    These techniques will require the use of the following methods:

  • Add an element to the front of the list
  • Count the number of elements in the list
  • Return the nth integer in the list (if the list has >n elements)
  • Return a pointer to the node that appears n nodes after the currently pointed to node



    Further Problems: Linked list functionality that may be required in the future: