[
next
] [
prev
] [
prev-tail
] [
tail
] [
up
]
2.3
Stacks (Last-In-First-Out)
stack()
void
push(const value_type& x)
void
pop()
value_type&
top()
bool
empty()
<..
ex-stack.cxx
..>
#include
<stack>
#include
<iostream>
using
namespace
std;
int
main()
{
stack<int>
s;
s.push(1);
s.push(2);
s.push(3);
while(
!
s.empty()
){
cout
<<
s.top()
<<
'
';
s.pop();
}
cout
<<
endl;
return
0;
}
-_-_-
3
2
1
Array Representation
Insert and delete in
O
(1) time.
One-way Linked Representation
Insert and delete in
O
(1) time
No advantage to double-linked representation.
[
stacks
]
[
next
] [
prev
] [
prev-tail
] [
front
] [
up
]