Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ problem Use the code provided to you under lab 6(or copy it from the end of the question), read and understand how it works.

c++ problem
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Use the code provided to you under lab 6(or copy it from the end of the question), read and understand how it works. Create a main.cpp file to test the functionalities provided to you. Add to the linked List class the functionalities required below. Test each new functionality added in the main before proceeding to the next. 1- 2- toString() member method that will print the values stored in each node. Example: If your linked list contains the numbers 6, 8 and 1 respectively, the toString) function should print [6, 8,1] removeValuelint val) member method that takes an int value. This method should remove all nodes containing the value passed to the function. For example: if your linked list contains the numbers 1, 4, 6, 4, 7, 8 and removeValue(4) was executed, your linked list should contain 1, 6, 7, a- b- printDuplicates() member method that will print values repeated more than once consecutively. For example, if your list contains 1, 4, 4, 6, 1,5 this function should print: 4 transferFrom () member method that accepts a second linked list as a parameter and that moves values from the second list to this list. It should append the elements in the second list to the first list and empty the second list. For example, suppose two lists store these sequences of values: list1: [8, 17, 2, 4] and list2: [1, 2, 3] The call of list1.transferFrom(list2); should leave the lists as follows: list1: [8, 17, 2, 4, 1,2,3] list2: [ c- d- e- sortlist() member method that will sort the linked list. Example: if your linked list contains the f- reverselist() member method that will reverse the linked list. Example: if your linked list contains B checkRange(int max, int min) member method that returns true if all elements in a given list are numbers 6, 8 and 1 respectively, the sortList() should fix the List to 1, 6, 8 respectively. the numbers 6, 8 and 1 respectively, the reverselist() should fix the list to 1, 8 and 6 respectively. within a given range (min, max), false otherwise. For example: if min was 2, max was 7 and the list was 1, 6, 9 and 2, we should return false since 1 is smaller than 2. h- evenNodes() member method that recursively return the number of even nodes. - oddNodes() member method that recursively return the number of odd nodes. Node.h Node public: int elem; // element in the node Node next; // Node(; Node (int data); pointer to the next element Node.cpp #include #include "Node . h" Node: : Node() elem e; next NULL; Node: :Node(int data)( elem = data; next = NULL; LinkedList.h include "Node"h" class LinkedList t private: Node "head; // A pointer to element of type Node public: LinkedList) LinkedList); void addEnd(int value);// Adds the given value to the end of the list. void addFront (int value);// add to front of list bool empty() const; I is list empty? int front() const; // get front element void removeFront); I/ remove front item list void removeEnd); //remove tail node int size(); int get(int index); 1/ Returns value in list at given index void remove(int index); // Removes value at given index from list void showList() LinkedList.cpp include Kiostream> using namespace std; #include "LinkedList"h" LinkedList::LinkedListO( head = NULL; LinkedList: :LinkedList)f while (lempty()) removeFront ); void LinkedList::addFront (int yalue) Node *v new Node(value); v->next-head; head = v; bool LinkedList::empty) constf return (head NULL) int LinkedList: :front() const f return head->elem; oid LinkedList::removeFrontO Node *v head; head head->next; delete v; V-NULL; oid LinkedList::showlist)( Node v head; cout elem next; cout next !=NULL){ current-current->next; current->next-v; void LinkedList: :removeEnd) if (head->next -NULL) removeFront); elsef Node v-head; while (v->next-mext-NULL){ vev-next; delete v->next; v->next NULL; int LinkedList: :size() int count; Node currenthead; while( current != NULL) { current current->next; count++ return count

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions