BIG C++
Cay Horstmann & Timothy Budd

Laboratory Notebook
Chapter 16 - Introduction to Data Structures


Your name:
Your email address:
Your student ID number:

Once this form has been customized for your institution, you can use this button to send your lab work. Be sure to read the instructions before starting your work.


Lab Objectives

To gain experience with


P1. Using Linked Lists

In this exercise, you should use the standard list template. Write a program that reads in a sequence of numbers and adds each input to the front of a list<int> object. (To add to the front, use the insert function with the begin iterator position.)

Then iterate through the list and print each element.

.

Run your program and describe its behavior.

.


P2. Implementing Linked List Operations

One very natural operation that is not already a feature of the List class in the textbook is appending an element to the head of a list.

Provide a new member function push_front(string e) class which will add the string e to the start of the original list.

For example, if the list a contains Harriet, Jim and Carolyn, and e is Harry, then the command a.push_front(e) changes a to contain Harry, Harriet, Jim, and Carolyn.

In this exercise, you must modify the pointers of the list. You may not use list iterators.

.

Test the push_front function by writing a main function that prints a list and then appends an employee to it. Then print out the combined list.


P3. Implementing a Stack

Using the Student class from Lab Notebook chapter 10, implement a stack to store students who have registered for a course. Your program should prompt the user for students and majors, store these to a stack, and then pop the entire stack when the user requests this,

Since this might not be quite correct for registration implement the same program as above, except with a queue.


P4. Other Standard Containers

Using the Student class, implement a map container and use the social security number as the index. Your program should ask the user for a list of students and social security numbers. It should then allow the user to search through the list of students using a social security number.


Do not forget to send your answers when you are finished.