Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QStack Class Reference

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

 #include <QStack>

Inherits: QVector<T>.

Note: All functions in this class are reentrant.

Public Functions

QStack ()
~QStack ()
T pop ()
void push ( const T & t )
void swap ( QStack<T> & other )
T & top ()
const T & top () const
  • 65 public functions inherited from QVector

Additional Inherited Members

  • 2 static public members inherited from QVector

Detailed Description

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.

Example:

     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.

Member Function Documentation

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

void QStack::swap ( QStack<T> & other )

Swaps stack other with this stack. This operation is very fast and never fails.

This function was introduced in Qt 4.8.

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

This is an overloaded function.

See also pop() and push().

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.8
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web