Question
Summary Construct a program that creates and prints a singly linked list. Learning Objectives - Construct a singly linked list. - Iterate through a list
Summary Construct a program that creates and prints a singly linked list.
Learning Objectives - Construct a singly linked list. - Iterate through a list and print the data.
Description Using C++, build a program that creates a linked list of integer data, and then prints the data. The data to be stored in the list is a series of integers input by the user. The program must include two classes and a driver program (C++), as described below. Be sure to follow the instructions as written.
File 1: LLNode Class The LLNode class is used to build the node objects that form the list, and must contain the following: Data members / fields: - integer to store the integer. Call this variable data. - LLNode pointer to store a reference or pointer to another LLNode object. Call this variable next. Functions / methods: - A one-argument constructor with an integer parameter to set the data. Set the next reference to 0 in this constructor. - public getters and setters for the above data members / fields.
File 2: LinkedList Class The LinkedList class is used to build the list object, and to add new node objects to the list. This class contains the following: Data members / fields: - LLNode pointer To store a reference or pointer to the first node in the list. Call this variable head. - LLNode pointer to store a reference or pointer to the last node in the list. Call this variable tail. Functions / methods: - public getters and setters for the above data members / fields. - public no-argument constructor to set the head and tail to 0. - public addNode function ->argument: one integer (representing the data to be stored) ->return value: none ->This function will pass the integer argument along to either addToHead or addToTail. - private addToHead -> argument: one integer representing the data -> return value: none ->This function instantiates an LLNode object using the argument data and adds the new node to the head of the list. - private addToTail -> argument:one integer representing the data -> return value: none -> This function instantiates an LLNode object using the argument data and adds the new node to the tail of the list. - public printList as described below. -> argument: none -> return value: none -> This function implements a loop to display the data from each node in the list, starting at the head and ending at the tail.
File 3: ListDriver Class / Program The ListDriver class is the driver for this program. This is where main will be located. You can add other functions or methods if you like or put everything in main. ListDriver must: 1. Instantiate a LinkedList object. 2. Implement a loop that prompts the user for an integer and calls the addNode function of the LinkedList object. Have the loop run at minimum 5 times, so at least 5 integers are added to the list. 3. Call the printList function of the LinkedList object.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started