Check out this quick tour to find the best demos and examples for you, and to see how the Felgo SDK can help you to develop your next app or game!
|qmake:||QT += core|
Note: All functions in this class are reentrant.
The QStack class is a template class that provides a stack.
A stack is a last in, first out (LIFO) structure. Items are added to the top of the stack using push() and retrieved from the top using pop(). The top() function provides access to the topmost item without removing it.
QStack<int> stack; stack.push(1); stack.push(2); stack.push(3); while (!stack.isEmpty()) cout << stack.pop() << endl;
The example will output 3, 2, 1 in that order.
QStack inherits from QVector. All of QVector's functionality also applies to QStack. For example, you can use isEmpty() to test whether the stack is empty, and you can traverse a QStack using QVector's iterator classes (for example, QVectorIterator). But in addition, QStack provides three convenience functions that make it easy to implement LIFO semantics: push(), pop(), and top().
QStack's value type must be an assignable data type. This covers most data types that are commonly used, but the compiler won't let you, for example, store a QWidget as a value; instead, store a QWidget *.
Removes the top item from the stack and returns it. This function assumes that the stack isn't empty.
Adds element t to the top of the stack.
This is the same as QVector::append().
Swaps stack other with this stack. This operation is very fast and never fails.
This function was introduced in Qt 4.8.
Returns a reference to the stack's top item. This function assumes that the stack isn't empty.
This is the same as QVector::last().
This is an overloaded function.