Qt:Документация 4.3.2/qstack

Материал из Wiki.crossplatform.ru

Версия от 10:11, 12 января 2009; Root (Обсуждение | вклад)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск
40px Внимание: Актуальная версия перевода документации находится здесь

__NOTOC__

Image:qt-logo.png

Главная · Все классы · Основные классы · Классы по группам · Модули · Функции

Image:trolltech-logo.png

Содержание

[править] QStack Class Reference
[модуль QtCore ]

The QStack class is a template class that provides a stack. Далее...

 #include <QStack>

Inherits QVector<T>.

Примечание: все функции в этом классе реентерабельны.

[править] Открытые функции

  • 62 public functions inherited from QVector

[править] Дополнительные унаследованные члены

  • 2 static public members inherited from QVector

[править] Подробное описание

The QStack class is a template class that provides a stack.

QStack<T> is one of Qt's generic container classes. It implements a stack data structure for items of a same type.

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 *.

See also QVector and QQueue.


[править] Описание функций-членов

[править]
QStack::QStack ()

Constructs an empty stack.

[править]
QStack::~QStack ()

Destroys the stack. References to the values in the stack, and all iterators over this stack, become invalid.

[править]
T QStack::pop ()

Removes the top item from the stack and returns it. This function assumes that the stack isn't empty.

See also top(), push(), and isEmpty().

[править]
void QStack::push ( const T & t )

Adds element t to the top of the stack.

This is the same as QVector::append().

See also pop() and top().

[править]
T & QStack::top ()

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().

See also pop(), push(), and isEmpty().

[править]
const T & QStack::top () const

Эта перегруженная функция предоставлена для удобства.

See also pop() and push().



Copyright © 2007 Trolltech Trademarks
Qt 4.3.2