1

Topic: To create the user classes - a deque, a stack (LIFO), queue (FIFO)

To create the user classes - a deque, a stack (LIFO), queue (FIFO) on the basis of a class list libraries STL. To write testing program which in a test mode fulfills operations over the generated difficult structures. The list of operations should be classical for difficult structures (taking into account restrictions on handling of specific structure):
Creation of empty difficult structure;
Element adding in structure before and after leaking elements;
Removal of any element in structure;
Search of an element with the given properties in structure;
Sorting of structure members;
Printing of structure members on the screen;
Removal of all structure.

#include <iostream>
#include <list>
using namespace std;
template <typename T>
class MyStack
{
public:
MyStack (initializer_list <T> l): m_data (l) {}
//void push (T &&x) {m_data.push_back (x);}
void push (const T &x) {m_data.push_back (x);}
void pop () {m_data.pop_back ();}
T& top () {return m_data.back ();}
const T& top () const {return m_data.back ();}
bool empty () const {return m_data.empty ();}
size_t size () const {return m_data.size ();}
void print () {
if (! m_data.empty ()) {
while (! m_data.empty ())
{
cout <<top () <<"";
pop ();
}
}
else
{
cout <<"stack empty" <<endl;
}
}
protected:
list <T> m_data;
};

It is possible to connect only lsit standard and to implement already on its basis classes for operation with difficult structures such classes as stack and queue it is impossible to use a week I think here above wrote the code but it not correct and on Monday it is necessary already help to hand over please

2

Re: To create the user classes - a deque, a stack (LIFO), queue (FIFO)

draka08 wrote:

but it not

than the code did not suit correct?  queues? smile