You are on page 1of 1

Sheet 4

1. The code in StringLinkedList folder is the “singly linked list of strings” class in your textbox
P.118 add the following function to the class and test them:
a. print() : prints the whole list.
b. addLast(e) : insert a new Node contains string e at the end of the list.
c. removeLast() : Remove last element in the list.
d. count() : returns the count of nodes in the list.

2. The code in DLinkedList folder is the doubly linked list class in your textbox P.126.
a) Convert it to a generic class (use template).
b) Add a count function that returns the number of nodes insides the linked list
c) add a [] operator to retrieve the data stored in the linked list.
d) Update [] operator such that a negative index means counting from last item to first one
(-1 last one, -2 the one before the last, …)
e) a function called removeAt that takes an index and remove the Node of that index.
Don’t add any new member data or other functions to the class.
3. Using the previousDLinkedList, write a main function that reads from the user as many
GameEntrys (class in P.104 and found in GameEntry folder) as he wishes then prints them
from first entry to last and from last entry to first.
Update the main to allow the user; after printing, to remove from the list as many
GameEntrys he wants then prints the list again.

4. Implement a sortedLinkedList class that insert the data into a linkedList in descending order.
The class should have a function to check the existence of a data in the sortedLinkedList and
also a function to remove a data (searching by its value not index) from the linkedList

5. Implement the class Scores of page 105 without a max limit.


6. A parking raw is 100m length. Many cars are entering it occupying any available empty
space in the raw and exiting from it leaving an empty space between cars. The best
technique for parking a new car is to occupy the smallest empty space that can fit the car.
Note that the car length is not the same for all cars (usually <=3m).
a) Design a class for simulating parking raw that can insert a car if possible, remove a car
and print the whole parking raw information.
b) Implement the class you designed in a)
c) Write a program that allows the user to repeatedly insert a new car, remove existing car
or print the information of the parking raw.

7. Implement a priorityQueue class that stores the data and their priority. The stored data
should be arranged in a ascending order from lowest priority to the highest one.

You might also like