description | title | ms.date | ms.topic | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: stack (STL/CLR) |
stack (STL/CLR) |
11/04/2016 |
reference |
|
|
6ee96b9f-8a33-4cf7-b7e0-6535c24bdefb |
The template class describes an object that controls a varying-length sequence of elements that has last-in first-out access. You use the container adapter stack
to manage an underlying container as a push-down stack.
In the description below, GValue
is the same as Value
unless the latter is a ref type, in which case it's Value^
. Similarly, GContainer
is the same as Container
unless the latter is a ref type, in which case it's Container^
.
template<typename Value,
typename Container>
ref class stack
: public
System::ICloneable,
Microsoft::VisualC::StlClr::IStack<GValue, GContainer>
{ ..... };
Value
The type of an element in the controlled sequence.
Container
The type of the underlying container.
Header: <cliext/stack>
Namespace: cliext
Type definition | Description |
---|---|
stack::const_reference |
The type of a constant reference to an element. |
stack::container_type |
The type of the underlying container. |
stack::difference_type |
The type of a signed distance between two elements. |
stack::generic_container |
The type of the generic interface for the container adapter. |
stack::generic_value |
The type of an element for the generic interface for the container adapter. |
stack::reference |
The type of a reference to an element. |
stack::size_type |
The type of a signed distance between two elements. |
stack::value_type |
The type of an element. |
Member function | Description |
---|---|
stack::assign |
Replaces all elements. |
stack::empty |
Tests whether no elements are present. |
stack::get_container |
Accesses the underlying container. |
stack::pop |
Removes the last element. |
stack::push |
Adds a new last element. |
stack::size |
Counts the number of elements. |
stack::stack |
Constructs a container object. |
stack::top |
Accesses the last element. |
stack::to_array |
Copies the controlled sequence to a new array. |
Property | Description |
---|---|
stack::top_item |
Accesses the last element. |
Operator | Description |
---|---|
stack::operator= |
Replaces the controlled sequence. |
operator!= (stack) |
Determines if a stack object isn't equal to another stack object. |
operator< (stack) |
Determines if a stack object is less than another stack object. |
operator<= (stack) |
Determines if a stack object is less than or equal to another stack object. |
operator== (stack) |
Determines if a stack object is equal to another stack object. |
operator> (stack) |
Determines if a stack object is greater than another stack object. |
operator>= (stack) |
Determines if a stack object is greater than or equal to another stack object. |
Interface | Description |
---|---|
xref:System.ICloneable | Duplicate an object. |
IStack<Value, Container> |
Maintain generic container adapter. |
The object allocates and frees storage for the sequence it controls through an underlying container of type Container
that stores Value
elements and grows on demand. The object restricts access to pushing and popping just the last element, implementing a last-in first-out queue (also known as a LIFO queue, or stack).
Replaces all elements.
void assign(stack<Value, Container>% right);
right
Container adapter to insert.
The member function assigns right.get_container()
to the underlying container. You use it to change the entire contents of the stack.
// cliext_stack_assign.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// assign a repetition of values
Mystack c2;
c2.assign(c1);
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
a b c
The type of a constant reference to an element.
typedef value_type% const_reference;
The type describes a constant reference to an element.
// cliext_stack_const_reference.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display reversed contents " c b a"
for (; !c1.empty(); c1.pop())
{ // get a const reference to an element
Mystack::const_reference cref = c1.top();
System::Console::Write("{0} ", cref);
}
System::Console::WriteLine();
return (0);
}
c b a
The type of the underlying container.
typedef Container value_type;
The type is a synonym for the template parameter Container
.
// cliext_stack_container_type.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents " a b c" using container_type
Mystack::container_type wc1 = c1.get_container();
for each (wchar_t elem in wc1)
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
The types of a signed distance between two elements.
typedef int difference_type;
The type describes a possibly negative element count.
// cliext_stack_difference_type.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// compute negative difference
Mystack::difference_type diff = c1.size();
c1.push(L'd');
c1.push(L'e');
diff -= c1.size();
System::Console::WriteLine("pushing 2 = {0}", diff);
// compute positive difference
diff = c1.size();
c1.pop();
c1.pop();
c1.pop();
diff -= c1.size();
System::Console::WriteLine("popping 3 = {0}", diff);
return (0);
}
a b c
pushing 2 = -2
popping 3 = 3
Tests whether no elements are present.
bool empty();
The member function returns true for an empty controlled sequence. It's equivalent to size() == 0
. You use it to test whether the stack
is empty.
// cliext_stack_empty.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
System::Console::WriteLine("size() = {0}", c1.size());
System::Console::WriteLine("empty() = {0}", c1.empty());
// clear the container and reinspect
c1.pop();
c1.pop();
c1.pop();
System::Console::WriteLine("size() = {0}", c1.size());
System::Console::WriteLine("empty() = {0}", c1.empty());
return (0);
}
a b c
size() = 3
empty() = False
size() = 0
empty() = True
The type of the generic interface for the container adapter.
typedef Microsoft::VisualC::StlClr::IStack<Value>
generic_container;
The type describes the generic interface for this template container adapter class.
// cliext_stack_generic_container.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// get interface to container
Mystack::generic_container^ gc1 = %c1;
for each (wchar_t elem in gc1->get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// modify generic and display original
gc1->push(L'd');
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// modify original and display generic
c1.push(L'e');
for each (wchar_t elem in gc1->get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
a b c
a b c d
a b c d e
The type of an element for use with the generic interface for the container.
typedef GValue generic_value;
The type describes an object of type GValue
that describes the stored element value for use with the generic interface for this template container class. (GValue
is either value_type
or value_type^
if value_type
is a ref type.)
// cliext_stack_generic_value.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// get interface to container
Mystack::generic_container^ gc1 = %c1;
for each (wchar_t elem in gc1->get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// display in reverse using generic_value
for (; !gc1->empty(); gc1->pop())
{
Mystack::generic_value elem = gc1->top();
System::Console::Write("{0} ", elem);
}
System::Console::WriteLine();
return (0);
}
a b c
a b c
c b a
Accesses the underlying container.
container_type^ get_container();
The member function returns a handle for underlying container. You use it to bypass the restrictions imposed by the container wrapper.
// cliext_stack_get_container.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents " a b c" using container_type
Mystack::container_type wc1 = c1.get_container();
for each (wchar_t elem in wc1)
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
Replaces the controlled sequence.
stack<Value, Container>% operator=(stack<Value, Container>% right);
right
Container adapter to copy.
The member operator copies right
to the object, then returns *this
. You use it to replace the controlled sequence with a copy of the controlled sequence in right
.
// cliext_stack_operator_as.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// assign to a new container
Mystack c2;
c2 = c1;
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
a b c
Removes the last element.
void pop();
The member function removes the last element of the controlled sequence, which must be non-empty. You use it to shorten the stack
by one element at the back.
// cliext_stack_pop.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// pop an element and redisplay
c1.pop();
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
a b
Adds a new last element.
void push(value_type val);
The member function inserts an element with value val
at the end of the controlled sequence. You use it to append another element to the stack.
// cliext_stack_push.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
The type of a reference to an element.
typedef value_type% reference;
The type describes a reference to an element.
// cliext_stack_reference.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// modify top of stack and redisplay
Mystack::reference ref = c1.top();
ref = L'x';
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
a b x
Counts the number of elements.
size_type size();
The member function returns the length of the controlled sequence. You use it to determine the number of elements currently in the controlled sequence. If all you care about is whether the sequence has nonzero size, see stack::empty
.
// cliext_stack_size.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
System::Console::WriteLine("size() = {0} starting with 3", c1.size());
// pop an item and reinspect
c1.pop();
System::Console::WriteLine("size() = {0} after popping", c1.size());
// add two elements and reinspect
c1.push(L'a');
c1.push(L'b');
System::Console::WriteLine("size() = {0} after adding 2", c1.size());
return (0);
}
a b c
size() = 3 starting with 3
size() = 2 after popping
size() = 4 after adding 2
The type of a signed distance between two elements.
typedef int size_type;
The type describes a non-negative element count.
// cliext_stack_size_type.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// compute positive difference
Mystack::size_type diff = c1.size();
c1.pop();
c1.pop();
diff -= c1.size();
System::Console::WriteLine("size difference = {0}", diff);
return (0);
}
a b c
size difference = 2
Constructs a container adapter object.
stack();
stack(stack<Value, Container>% right);
stack(stack<Value, Container>^ right);
explicit stack(container_type% wrapped);
right
Object to copy.
wrapped
Wrapped container to use.
The constructor:
stack();
creates an empty wrapped container. You use it to specify an empty initial controlled sequence.
The constructor:
stack(stack<Value, Container>% right);
creates a wrapped container that is a copy of right.get_container()
. You use it to specify an initial controlled sequence that is a copy of the sequence controlled by the stack
object right
.
The constructor:
stack(stack<Value, Container>^ right);
creates a wrapped container that is a copy of right->get_container()
. You use it to specify an initial controlled sequence that is a copy of the sequence controlled by the stack
object *right
.
The constructor:
explicit stack(container_type% wrapped);
uses the existing container wrapped
as the wrapped container. You use it to construct a stack
from an existing container.
// cliext_stack_construct.cpp
// compile with: /clr
#include <cliext/stack>
#include <cliext/vector>
typedef cliext::stack<wchar_t> Mystack;
typedef cliext::vector<wchar_t> Myvector;
typedef cliext::stack<wchar_t, Myvector> Mystack_vec;
int main()
{
// construct an empty container
Mystack c1;
System::Console::WriteLine("size() = {0}", c1.size());
// construct from an underlying container
Myvector v2(5, L'x');
Mystack_vec c2(v2);
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// construct by copying another container
Mystack_vec c3(c2);
for each (wchar_t elem in c3.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// construct by copying another container through handle
Mystack_vec c4(%c2);
for each (wchar_t elem in c4.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
size() = 0
x x x x x
x x x x x
x x x x x
Copies the controlled sequence to a new array.
cli::array<Value>^ to_array();
The member function returns an array containing the controlled sequence. You use it to obtain a copy of the controlled sequence in array form.
// cliext_stack_to_array.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// copy the container and modify it
cli::array<wchar_t>^ a1 = c1.to_array();
c1.push(L'd');
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// display the earlier array copy
for each (wchar_t elem in a1)
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c d
a b c
Accesses the last element.
reference top();
The member function returns a reference to the last element of the controlled sequence, which must be non-empty. You use it to access the last element, when you know one exists.
// cliext_stack_top.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// inspect last item
System::Console::WriteLine("top() = {0}", c1.top());
// alter last item and reinspect
c1.top() = L'x';
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
top() = c
a b x
Accesses the last element.
property value_type top_item;
The property accesses the last element of the controlled sequence, which must be non-empty. You use it to read or write the last element, when you know one exists.
// cliext_stack_top_item.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// inspect last item
System::Console::WriteLine("top_item = {0}", c1.top_item);
// alter last item and reinspect
c1.top_item = L'x';
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
top_item = c
a b x
The type of an element.
typedef Value value_type;
The type is a synonym for the template parameter Value
.
// cliext_stack_value_type.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display reversed contents " a b c" using value_type
for (; !c1.empty(); c1.pop())
{ // store element in value_type object
Mystack::value_type val = c1.top();
System::Console::Write("{0} ", val);
}
System::Console::WriteLine();
return (0);
}
c b a
Stack
not equal comparison.
template<typename Value,
typename Container>
bool operator!=(stack<Value, Container>% left,
stack<Value, Container>% right);
left
Left container to compare.
right
Right container to compare.
The operator function returns !(left == right)
. You use it to test whether left
isn't ordered the same as right
when the two stacks are compared element by element.
// cliext_stack_operator_ne.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// assign to a new container
Mystack c2;
c2.push(L'a');
c2.push(L'b');
c2.push(L'd');
// display contents " a b d"
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
System::Console::WriteLine("[a b c] != [a b c] is {0}",
c1 != c1);
System::Console::WriteLine("[a b c] != [a b d] is {0}",
c1 != c2);
return (0);
}
a b c
a b d
[a b c] != [a b c] is False
[a b c] != [a b d] is True
Stack
less than comparison.
template<typename Value,
typename Container>
bool operator<(stack<Value, Container>% left,
stack<Value, Container>% right);
left
Left container to compare.
right
Right container to compare.
The operator function returns true if, for the lowest position i
for which !(right[i] < left[i])
it's also true that left[i] < right[i]
. Otherwise, it returns left->size() < right->size()
. You use it to test whether left
is ordered before right
when the two stacks are compared element by element.
// cliext_stack_operator_lt.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// assign to a new container
Mystack c2;
c2.push(L'a');
c2.push(L'b');
c2.push(L'd');
// display contents " a b d"
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
System::Console::WriteLine("[a b c] < [a b c] is {0}",
c1 < c1);
System::Console::WriteLine("[a b c] < [a b d] is {0}",
c1 < c2);
return (0);
}
a b c
a b d
[a b c] < [a b c] is False
[a b c] < [a b d] is True
Stack
less than or equal comparison.
template<typename Value,
typename Container>
bool operator<=(stack<Value, Container>% left,
stack<Value, Container>% right);
left
Left container to compare.
right
Right container to compare.
The operator function returns !(right < left)
. You use it to test whether left
isn't ordered after right
when the two stacks are compared element by element.
// cliext_stack_operator_le.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// assign to a new container
Mystack c2;
c2.push(L'a');
c2.push(L'b');
c2.push(L'd');
// display contents " a b d"
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
System::Console::WriteLine("[a b c] <= [a b c] is {0}",
c1 <= c1);
System::Console::WriteLine("[a b d] <= [a b c] is {0}",
c2 <= c1);
return (0);
}
a b c
a b d
[a b c] <= [a b c] is True
[a b d] <= [a b c] is False
Stack
equal comparison.
template<typename Value,
typename Container>
bool operator==(stack<Value, Container>% left,
stack<Value, Container>% right);
left
Left container to compare.
right
Right container to compare.
The operator function returns true only if the sequences controlled by left
and right
have the same length and, for each position i
, left[i] == right[i]
. You use it to test whether left
is ordered the same as right
when the two stacks are compared element by element.
// cliext_stack_operator_eq.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// assign to a new container
Mystack c2;
c2.push(L'a');
c2.push(L'b');
c2.push(L'd');
// display contents " a b d"
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
System::Console::WriteLine("[a b c] == [a b c] is {0}",
c1 == c1);
System::Console::WriteLine("[a b c] == [a b d] is {0}",
c1 == c2);
return (0);
}
a b c
a b d
[a b c] == [a b c] is True
[a b c] == [a b d] is False
Stack
greater than comparison.
template<typename Value,
typename Container>
bool operator>(stack<Value, Container>% left,
stack<Value, Container>% right);
left
Left container to compare.
right
Right container to compare.
The operator function returns right < left
. You use it to test whether left
is ordered after right
when the two stacks are compared element by element.
// cliext_stack_operator_gt.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// assign to a new container
Mystack c2;
c2.push(L'a');
c2.push(L'b');
c2.push(L'd');
// display contents " a b d"
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
System::Console::WriteLine("[a b c] > [a b c] is {0}",
c1 > c1);
System::Console::WriteLine("[a b d] > [a b c] is {0}",
c2 > c1);
return (0);
}
a b c
a b d
[a b c] > [a b c] is False
[a b d] > [a b c] is True
Stack
greater than or equal comparison.
template<typename Value,
typename Container>
bool operator>=(stack<Value, Container>% left,
stack<Value, Container>% right);
left
Left container to compare.
right
Right container to compare.
The operator function returns !(left < right)
. You use it to test whether left
isn't ordered before right
when the two stacks are compared element by element.
// cliext_stack_operator_ge.cpp
// compile with: /clr
#include <cliext/stack>
typedef cliext::stack<wchar_t> Mystack;
int main()
{
Mystack c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents " a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// assign to a new container
Mystack c2;
c2.push(L'a');
c2.push(L'b');
c2.push(L'd');
// display contents " a b d"
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
System::Console::WriteLine("[a b c] >= [a b c] is {0}",
c1 >= c1);
System::Console::WriteLine("[a b c] >= [a b d] is {0}",
c1 >= c2);
return (0);
}
a b c
a b d
[a b c] >= [a b c] is True
[a b c] >= [a b d] is False