
Programming Assignment 2 โ CSC3410
Due Date: Thursday, February 28, 2008
Objective: Learning how to implement and use linked lists.
All the programs source code and the output screens must be submitted together. A
hardcopy of these files are due in class on the due date and students also have to
submit their .cpp and .h files and the executable file as attachments by email on the due
date.
1. Write a program that uses a random number generator. ( Use rand() function
(header file stdlib.h), srand()and time (NULL) function (header file: <time.h> to seed
the generator. ) Generate 6 integers using your random number generator and
insert these 6 items one by one in a linked list. Print out the elements from head
to tail order. Then, delete the last element from the linked list and print the list
again.
Insert the following numbers in your linked list: 1, 2, 3, 4, 3, 6, 7
Now, write a get_count() function that counts the number of times a given
integer occurs in the list. To test your function, search for the number โ3โ in your
linked list and print out the number of times it has occurred.
2. Using the same list above, write a get_Nth() function that takes the linked list
above and an integer index and returns the data value stored in that node at
that index position. To test your function, return the data value stored at the 4th
index. Assume that the first nodeโs index is 1.
3. Call the linked list above โaโ. Create another linked list โbโ and insert the
following elements into b: 10, 20, 30. Write an append_lists() function that takes
two lists โaโ and โbโ and append b onto the end of a. and then sets b to NULL.
Print a. In this case, b is empty and a has all bโs elements appended to it.