CSC3410 Programming Assignment 2: Implementing and Using Linked Lists - Prof. Zejin Ding, Assignments of Data Structures and Algorithms

This programming assignment for csc3410 introduces students to implementing and using linked lists. The assignment includes writing a program that generates random numbers and inserts them into a linked list, creating functions to get the count of a given integer and retrieve the data value at a specific index, and appending one linked list to another. Students must submit both hardcopies and digital files.

Typology: Assignments

Pre 2010

Uploaded on 08/31/2009

koofers-user-fkt
koofers-user-fkt 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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

Partial preview of the text

Download CSC3410 Programming Assignment 2: Implementing and Using Linked Lists - Prof. Zejin Ding and more Assignments Data Structures and Algorithms in PDF only on Docsity!

Programming Assignment 2 – CSC

Due Date: Thursday, February 2 8 , 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.