C++ This assignment is designed for you to develop a template linked list loaded with new features. The reason we want a

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

C++ This assignment is designed for you to develop a template linked list loaded with new features. The reason we want a

Post by answerhappygod »

C++
This assignment is designed for you to develop a template linked
list loaded with new features. The reason we want a powerful linked
list is because we will be using this list to create our stack and
queue. The more functionality of your linked list, the easier it is
to implement the other data structures.
Instructions
Modify your LinkedList from the Linked List Starter Lab in Unit
11. You template Linked List should have the following
functionality:
Remember, a linked list is a group of nodes linked
together. The Node struct has three member variables,
next, prev, and data. The variable
data stores the data that we are adding to our list. The
variable next is a pointer that points to the next node in
the list and prev is a pointer pointing to the previous
node in the list.
Please overload the insertion operator (<<) to print
all the items in the list.
Also, to insert an item at the end of the list, create both a
function to do so, as well as overloading the +=
operator.
Also determine if your class needs the big 3 (Destructor, Copy
Constructor, Assignment Operator), and if so, make sure to
implement them.
Submit your class files, as well as a sample of your tests. Your
test should include adding items to both the end and beginning of
your list as well as printing the list:
/*Here is my previous lab for reference
#include <bits/stdc++.h>
using namespace std;
class Node
{
public:
int value;
Node *next;
};
class LinkedList{
public:
Node* head;
LinkedList()
{
head = NULL;
}
int operator += (const int data){
Node* new_node = new Node();
new_node->value = data;
new_node->next = NULL;
Node *last = head;
if (head == NULL)
{
head = new_node;
}
else
{
while (last->next != NULL)
last = last->next;
last->next = new_node;
}
return 0;
}
int operator << (const LinkedList obj)
{
Node *node = obj.head;
while (node != NULL)
{
cout<<" "<<node->value;
node = node->next;
}
return 0;
}
void insertBefore(int data)
{
Node* new_node = new Node();
new_node->value = data;
new_node->next = head;
head = new_node;
}
void insertAfter(int data)
{
Node* new_node = new Node();
new_node->value = data;
new_node->next = NULL;
Node *last = head;
if (head == NULL)
{
head = new_node;
}
else{
while (last->next != NULL)
last = last->next;
last->next = new_node;
}
}
void printList()
{
Node *node = head;
while (node != NULL)
{
cout<<" "<<node->value;
node = node->next;
}
}
};
int main()
{
LinkedList list;
list.insertAfter(5);
list << list;
cout << "\n";
list += 8;
list << list;
cout << "\n";
list.insertBefore(6);
list << list;
cout << "\n";
return 0;
}
*/
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply