Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use this program https://repl.it/@YBYUN/List, Add two new functions named isSorted() and removeAll() . The function isSorted() checks if the list is sorted in the ascending

use this program https://repl.it/@YBYUN/List, Add two new functions named isSorted() and removeAll().

The function isSorted() checks if the list is sorted in the ascending order or not.

bool isSorted();

For example, if a list contains 10, 30, and 20, the function should return false. However, if the list has 10, 20, 20, and 30, it should return true. Note that if the list is empty or has only one number, the function should return true.

The function removeAll() removes the value given in an argument in the list.

bool removeAll(int value);

For example, if a list contains 10, 30, and 20, remove(30) will remove the value 30 from the list and return true. For the list 10, 20, and 20, remove(40) will not remove anything from the list and return false. If a list has duplication like 10, 30, 30, 20, and 30, remove(30) will remove all 30s in the list and return true. So, the result list will have 10 and 20.

Sample Test Program:

// This is a sample program to test the new functions.

// Read the execution result of the program carefully

// to identify the operations of new functions

int main()

{

List intList;

intList.insert(10, 0);

intList.insert(20, 1);

cout << (intList.isSorted() ? "Yes" : "No") << endl;

intList.insert(15, 2);

cout << (intList.isSorted() ? "Yes" : "No") << endl;

intList.insert(20, 3);

intList.display();

intList.removeAll(20);

intList.display();

intList.removeAll(10);

intList.display();

return 0;

}

Execution Result:

Yes

No

10 20 15 20

10 15

15

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions