Question: C++ code: (1) Implement the concepts of a union, and difference as defined noted in Chapter 1 questions 6, and 8 using a linked list.
C++ code:
(1) Implement the concepts of a union, and difference as defined noted in Chapter 1 questions 6, and 8 using a linked list. You should not use arrays, dynamic arrays or the STL vector or STL list classes. Note: You can follow the books definition of union (so 3 items with some duplicates + 4 items with some duplicates = 7 items with duplicates...duplicates are also allowed for the difference, per the description)
You will be linking a series of nodes together to implement a single linked list class. Define a Node as a struct that holds a character (like they did in the book) and a pointer to another Node:
struct Node {
char data;
Node* nextPtr;
};
Then define a LinkedList class which has (at a minimum) these member functions:
LinkedList();
~LinkedList();
bool insertAtFront(char value);
bool insertBeforePosition(char value, int index); //first Node after headptr is 1
//false if pos zero or out of range
bool insertAtBack(char value);
bool deleteAtFront(); bool deletePosition(int index); //first Node after headptr is 1
//false if pos zero or out of range
bool deleteAtBack();
//false if empty
friend ostream& operator << (ostream &out, LinkedList list);
Implement each of these functions to provide the correct functionality. These functions return true if successful in inserting or deleting, otherwise they return false (indicating the operation was not successful).
Finally, create an overloaded + operator to handle the Union of two linked lists and an overloaded - operator to handle the Difference of two linked lists. (similar to the rules of HW02)
Because we are dealing with pointers you should have both a LinkedList Constructor and Destructor. Remember that you do not directly call a Constructor or Destructor Function. The Destructor is automatically called when the variable loses scope or the program ends. Remember, that we are dealing with not just one dynamically allocated Node (with the new operator), but many, so you will have to start at the head of the list and go until the Node points to nullptr. Then keep deleting the previous Node pointer until there are no Nodes left to delete.
(2) To verify your LinkedList class, write a main function that takes two lines of characters from the input file input.txt (you can create two lines of characters separated by spaces) and store each line of characters into two separate linked lists. Then using these two lists, perform the Union and set Difference of the characters from the file, and print the results to the console.
(3) Please also complete an asymptotic (Big O) analysis of your insertAtFront() and insertAtBack() member functions. Place this in a file called analysis.txt.
bool insertAtFront();
bool insertBeforePosition(int
index);
bool insertAtBack();
bool deleteAtFront();
bool deleteBeforePosition(int
index);
bool deleteAtBack();
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
