1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the core module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
31
\brief The QStack class is a template class that provides a stack.
38
QStack\<T\> is one of Qt's generic \l{container classes}. It implements
39
a stack data structure for items of a same type.
41
A stack is a last in, first out (LIFO) structure. Items are added
42
to the top of the stack using push() and retrieved from the top
43
using pop(). The top() function provides access to the topmost
44
item without removing it.
52
while (!stack.isEmpty())
53
cout << stack.pop() << endl;
56
The example will output 3, 2, 1 in that order.
58
QStack inherits from QVector. All of QVector's functionality also
59
applies to QStack. For example, you can use isEmpty() to test
60
whether the stack is empty, and you can traverse a QStack using
61
QVector's iterator classes (for example, QVectorIterator). But in
62
addition, QStack provides three convenience functions that make
63
it easy to implement LIFO semantics: push(), pop(), and top().
65
QStack's value type must be an \l{assignable data type}. This
66
covers most data types that are commonly used, but the compiler
67
won't let you, for example, store a QWidget as a value; instead,
76
Constructs an empty stack.
82
Destroys the stack. References to the values in the stack, and all
83
iterators over this stack, become invalid.
87
\fn void QStack::push(const T& t)
89
Adds element \a t to the top of the stack.
91
This is the same as QVector::append().
99
Returns a reference to the stack's top item. This function
100
assumes that the stack isn't empty.
102
This is the same as QVector::last().
104
\sa pop(), push(), isEmpty()
108
\fn const T& QStack::top() const
118
Removes the top item from the stack and returns it. This function
119
assumes that the stack isn't empty.
121
\sa top(), push(), isEmpty()