Question: /* Single Linked List Implementation in C++ */ #include using namespace std; class LinkedList{ private: struct node{ node *next; // Dynamic Data member. int data;

/*

Single Linked List Implementation in C++

*/

#include

using namespace std;

class LinkedList{

private:

struct node{

node *next; // Dynamic Data member.

int data;

};

node *head; // Dynamic data Member.

int size; // Static Date Member.

public:

// Default Constructor

LinkedList():head(NULL), size(0){}

// Custom Constructor

LinkedList(int data){

node* newNode = new node;

newNode->data = data;

newNode->next = NULL;

head = newNode;

size = 1;

}

//Destructor

~LinkedList(){

deleteList();

cout

}

// Copy Constructor

LinkedList(const LinkedList& rhs){

if(rhs.head == NULL){

head = NULL;

size = 0;

}

else{

head = new node;

node* rhsHead = rhs.head;

node* link = head;

link->data = rhsHead->data;

rhsHead = rhsHead->next;

while(rhsHead != NULL){

node* secondNode = new node;

secondNode->data = rhsHead->data;

//secondNode->next = NULL;

link->next = secondNode;

link = link->next;

rhsHead = rhsHead->next;

}

link->next = NULL;

}

}

// Assignment operator overloading

LinkedList& operator=(const LinkedList& rhs){

if(head == rhs.head){

return *this;

}

if(rhs.head == NULL){

deleteList();

return *this;

}

deleteList();

head = new node;

node* rhsHead = rhs.head;

node* link = head;

link->data = rhsHead->data;

rhsHead = rhsHead->next;

while(rhsHead != NULL){

node* secondNode = new node;

secondNode->data = rhsHead->data;

//secondNode->next = NULL;

link->next = secondNode;

link = link->next;

rhsHead = rhsHead->next;

}

link->next = NULL;

return *this;

}

// Getters

void printList(){

if(head == NULL)

return;

node* current = head;

while(current->next != NULL){

cout";

current = current->next;

}

cout

}

int listSize(){

return size;

}

// Setters || Mutators

void append(int data){

node* newNode = new node;

newNode->data = data;

newNode->next = NULL;

if(head == NULL){

head = newNode;

size++;

return;

}

node* current = head;

while(current->next != NULL)

current = current->next;

current->next = newNode;

}

void insertFront(int data){

node* newNode = new node;

newNode->data = data;

newNode->next = NULL;

newNode->next = head;

head = newNode;

}

int frontElement(){

return -1;

}

int lastElement(){

return -1;

}

void deleteFront(){

if(head == NULL)

return;

node* current = head;

head = head->next;

delete current;

}

bool findElement(int value){

return false;

}

void deleteElement(int value){

}

void deleteList(){

if(head == NULL)

return;

node* current = head;

while(current->next != NULL){

node* temp = current;

current = current->next;

delete temp;

}

delete current;

head = NULL;

size = 0;

}

void deleteDuplicates(int value){

}

void listReverse(){

}

};

int main(){

LinkedList* l1 = new LinkedList();

LinkedList* l2 = new LinkedList(1);

l1->append(90);

(*l1).append(91);

l1->append(92);

// LinkedList l3 = l1; // copy constructor will be called

l2->append(2);

l1->printList();

l2->printList();

*l2 = *l1; // Assignment operator will be called

l2->append(5);

cout

l1->printList();

l2->printList();

delete l1;

delete l2;

return 0;

}

Need to edit the code above to answer 1-10, on the screenshot below.

/* Single Linked List Implementation in C++ */ #include using namespace std;

This Assignment contains two parts and you have to submit a separate .zip file for each part. Implement a singly linked list ADT to store a collection of integers. Implement a Double linked List ADT to store a collection of integers. (You are allowed to extend the demo code posted on iLearn for this homework). Make sure you test these new functions in the main() function. Your ADT will include the following member functions: a default constructor the *big-3*: destructor, copy constructor and overloaded assignment operator a member function lnsertFront(int data) that inserts a number at the front of the list a member function append(int data) that appends a number at the back of the list. a member function popFirst() that removes first element of the list. a member function popLast() that removes last element of the list. a member function that deletes a number and all its copies from the list, where these copies can be located anywhere in the list. a member function MtoLastElement(int M) that returns Mth to the last element of a list such that when M = 0, the last element of the list is returned. a member function that returns the size of the list. an overloaded put operator (

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!