Answer to Question #235348 in C++ for Myname

Question #235348
WAP to implement the Linear linked list. Perform the following operations on the linked
list:
 Creating an empty linked list
 Adding the numbers at the beginning of the linked list.
 Addition of numbers after a particular location.
 Counting the no of nodes.
 Displaying the linked list.
1
Expert's answer
2021-09-10T06:49:38-0400
#include <iostream>
#include <list>
#include <iterator>


using namespace std;


class MyList : public list<int>
{
public:
    void showlist()
    {
        list <int> ::iterator it;
        for (it = this->begin(); it != this->end(); ++it)
            cout << *it << " ";
        cout << '\n';
    }
    int countlist()
    {
        int count = 0;
        list <int> ::iterator it;
        for (it = this->begin(); it != this->end(); ++it)
            count++;
        return count;
    }


private:
};


int main()
{
	MyList test;        // creating empty list
    // Adding the numbers at the beginning of the linked list
    cout << "Insert 3 values: " << endl;
    test.push_front(2);
    test.push_front(5);
    test.push_front(1);
    cout << "Display values in list: ";
    test.showlist();    // Displaying the linked list
    cout << "Number nodes in linked list: " << test.countlist() << endl;


    system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS