Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can someone please help me with the second .cpp file, which is the implementation file for the linked list class?? the instructor gave us three
can someone please help me with the second .cpp file, which is the implementation file for the linked list class?? the instructor gave us three different files and the last one is the one that needs to be worked ONLY, we cannot do anything to the main .cpp file nor the header file:
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ // Program: Lab 04 // Author: // Course: CSCI/CMPE 2380 // Description: This program builds a doubly linked list from entered numbers //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ #include "LinkedList.h" int main() { //initialize our pointer to NULL LinkedList LL; int input; cout<<"Please input some numbers."<>input; while( !cin ) { cin.clear(); cin.ignore(2000, ' '); cout<<"Not a legal integer"< > input; } //if they're positive, add them to the linked list if(input > 0) LL.Add(input); } while( input > 0 ); cout<<"The numbers you entered are:"<
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ // Program: Lab 04 Header // Author: // Course: CSCI/CMPE 2380 // Description: This is the header file for the linked list class //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ #includeusing namespace std; //a basic node for a doubly linked list with data struct Node { int data; Node *next; Node *prev; }; //a linked list class we will use class LinkedList { public: LinkedList(); ~LinkedList(); void Add(int); void PrintList(); private: void DeleteList(); Node* Head; };
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ // Program: Lab 04 // Author: // Course: CSCI/CMPE 2380 // Description: This is the implementation file for the linked list class //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ #include "LinkedList.h" //constructor LinkedList::LinkedList() { //should set head pointer } //destructor LinkedList::~LinkedList() { //should call delete list } /* This function adds a new node to the end of the doubly linked list. If it is the first node, then head will still be NULL. Here we are using head directly, so that when we create a new node it stores it in the variable being used in main. head <=> [2|] <=> [8|] <=> [6|X] */ void LinkedList::Add(int newdata) { //create a new node to hold the data with a terminal (NULL) next pointer //check whether head has been initialized (is NULL) //if not, make the new node head and set prev //if head has been initialized //find the end of the chain with a pointer //add the new node on to the last node in the list //set pointers both forward and backwards } //This function walks through the list and prints the integer for each of the nodes //We are using a copy of head, so changing it's value does not alter the //variable in main void LinkedList::PrintList() { //walk through the list starting at head //print the data for the current node } //This function walks through the list and deletes each node void LinkedList::DeleteList() { //make sure the list has data if(Head != NULL) { //delete first node Node *next = Head->next; delete Head; //loop through list deleting each node while (next != NULL) { Head = next; next = Head->next; delete Head; } //set pointer to null Head = NULL; } }
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