Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Class called List , it must meet all of those requirements stated and follow the

ID: 3742687 • Letter: C

Question

Class called List, it must meet all of those requirements stated and follow the sudo code laid out below the picture.

Sudo Code

/*
* Template class that will be used to hold pointers to things
* Sorted array list, depends on operator< existing for the type being held
*/

#ifndef ARRAY_LIST_HPP
#define ARRAY_LIST_HPP

// Any necessary includes

// It's a template class
class List {
public:
// Default Constructor
// Constructor that takes first item of list
// Copy Constructor
// Move Constructor
// Destructor
// Copy assignment operator overload
// Move assignment operator overload
// function size; does not throw exceptions
// function capacity; does not throw exceptions
// function insert; does not throw exceptions
// function erase; throws underflow_error if empty, range_error if item doesn't exist
// function at; throws out_of_range exception; returns a const value
// function at; throws out_of_range exception; returns l-value
// function search; throws domain error if item doesn't exist
private:
// variable that gives us our dynamic array
unsigned int _size;
unsigned int _capacity;
};


// LIST CLASS FUNCTION IMPLEMENTATIONS

#endif

List class requirements - The list shall only be expected to work when it holds pointers to whatever data type - The list shall hold its items in a dynamic array The use of the vector class is not allowed - The list shall be sorted In the case of Books, they should sort themselves by author, then title The List only cares about a

Explanation / Answer

#include <iostream>
#include <forward_list>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
    forward_list<int> fl, fl1 = {5, 6, 3, 2, 7};
    forward_list<int>::iterator it;
    int choice, item;
    while (1)
    {
        cout<<" ---------------------"<<endl;
        cout<<"Forward_List Implementation in Stl"<<endl;
        cout<<" ---------------------"<<endl;
        cout<<"1.Insert Element at the Front"<<endl;
        cout<<"2.Delete Element at the Front"<<endl;
        cout<<"3.Front Element of Forward List"<<endl;
        cout<<"4.Resize Forward List"<<endl;
        cout<<"5.Remove Elements with Specific Values"<<endl;
        cout<<"6.Remove Duplicate Values"<<endl;
        cout<<"7.Reverse the order of elements"<<endl;
        cout<<"8.Sort Forward List"<<endl;
        cout<<"9.Merge Sorted Lists"<<endl;
        cout<<"10.Display Forward List"<<endl;
        cout<<"11.Exit"<<endl;
        cout<<"Enter your Choice: ";
        cin>>choice;
        switch(choice)
        {
        case 1:
            cout<<"Enter value to be inserted at the front: ";
            cin>>item;
            fl.push_front(item);
            break;
        case 2:
            item = fl.front();
            fl.pop_front();
            cout<<"Element "<<item<<" deleted"<<endl;
            break;
        case 3:
            cout<<"Front Element of the Forward List: ";
            cout<<fl.front()<<endl;
            break;
        case 4:
            cout<<"Enter new size of Forward List: ";
            cin>>item;
            if (item <= fl.max_size())
                fl.resize(item);
            else
                fl.resize(item, 0);
            break;
        case 5:
            cout<<"Enter element to be deleted: ";
            cin>>item;
            fl.remove(item);
            break;
        case 6:
            fl.unique();
            cout<<"Duplicate Items Deleted"<<endl;
            break;
        case 7:
            fl.reverse();
            cout<<"Forward List reversed"<<endl;
            break;
        case 8:
            fl.sort();
            cout<<"Forward List Sorted"<<endl;
            break;
        case 9:
            fl1.sort();
            fl.sort();
            fl.merge(fl1);
            cout<<"Forward List Merged after sorting"<<endl;
            break;
        case 10:
            cout<<"Elements of Forward List: ";
            for (it = fl.begin(); it != fl.end(); it++)
                cout<<*it<<" ";
            cout<<endl;
            break;
        case 11:
            exit(1);
        break;
        default:
            cout<<"Wrong Choice"<<endl;
        }
    }
    return 0;
}