#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;
}
Comments
Leave a comment