you need
  • - a text editor or IDE;
  • - translator with the programming language used.
Guide
1
Use the methods of the stack specifically designed for cleaning.They are present in most of the classes of different libraries and frameworks.For example, the Stack class of the .NET method has Clear.An example of its application in C # might look like this:
Stack oStack = new Stack ();// Create the stack
oStack.Push ("000");// Fill the stack
oStack.Push ("111");
oStack.Clear ();// Clean up the stack
2
method of changing the number of elements of container classes, which often builds functional classes stacks can be also used for cleaning.It is necessary simp
ly to reduce the current number of elements to zero.For example, a template class QStack Qt libraries inherited from the template class QVector, which has a method resize.An example of its use can be so:
QStack & lt; int & gt;oStack;// Declaration object stack
for (int i = 0; i & lt; 10; i ++) oStack.push (i);// Fill the stack
oStack.resize (0);// Clean up the stack
3
purification of the stack can usually be done through the assignment operator, which is often implemented in the corresponding classes.To do this, the object is to be cleansed of the stack you want to assign a temporary object created a default constructor.For example, the template stack class standard library of C ++, which is an adapter template container classes do not have the methods of any change in the number or delete all items.Clear it is possible so:
std :: stack & lt; int, std :: list & lt; int & gt;& gt;oStack;// Declaration object stack
for (int i = 0; i & lt; 10; i ++) oStack.push (i);// Fill the stack
oStack = std :: stack & lt; int, std :: list & lt; int & gt;& gt; ();// Clean up the stack
4
Clean the lens stack by calling the copy constructor by issuing new c argument object, a default constructor:
std :: stack & lt; int, std :: list & lt; int & gt;& gt;oStack;// Declaration object stack
for (int i = 0; i & lt; 10; i ++) oStack.push (i);// Fill the stack
new std :: stack & lt; int, std :: list & lt; int & gt;& gt; (oStack);// Clean up the stack
5
stack can be cleaned by sequentially retrieve all items using the appropriate methods:
std :: stack & lt; int, std :: list & lt; int & gt;& gt;oStack;// Declaration object stack
for (int i = 0; i & lt; 10; i ++) oStack.push (i);// Fill the stack
while (! OStack.empty ()) oStack.pop (); // cleaning stack
However, this approach has the time complexity is linearly dependent on the number of items in the stack.Therefore, its use is not rational.