< index < 8. All purposes container < 8.3 Basic list operations | ===================================== 8.4 Basic stack operations ===================================== | > 8.5 Iterators

You can push an element on the stack (append it to the end of the list) :

    C++ : template <class T> void TCODList::push(const T elt)
    C   : void TCOD_list_push(TCOD_list_t l, const void * elt)

Parameter | Description
--- | ---
elt | Element to append to the list.
l | In the C version, the list handler, returned by a constructor.

Example :

    C++ : TCODList<int> intList; // the list is empty (contains 0 elements)
          intList.push(5); // the list contains 1 element at position 0, value = 5
          intList.push(2); // the list contains 2 elements : 5,2
    C   : TCOD_list_t intList = TCOD_list_new();
          TCOD_list_push(intList,(const void *)5);
          TCOD_list_push(intList,(const void *)2);

You can pop an element from the stack (remove the last element of the list).

    C++ : template <class T> T TCODList::pop()
    C   : void * TCOD_list_pop(TCOD_list_t l)

Parameter | Description
--- | ---
l | In the C version, the list handler, returned by a constructor.

Example :

    C++ : TCODList<int> intList; // the list is empty (contains 0 elements)
          intList.push(5); // the list contains 1 element at position 0, value = 5
          intList.push(2); // the list contains 2 elements : 5,2
          int val = intList.pop(); // val == 2, the list contains 1 element : 5
          val = intList.pop(); // val == 5, the list is empty
    C   : TCOD_list_t intList = TCOD_list_new();
          TCOD_list_push(intList,(const void *)5);
          TCOD_list_push(intList,(const void *)2);
          int val = (int)TCOD_list_pop(intList);
          val = (int)TCOD_list_pop(intList);

You can read the last element of the stack without removing it :

    C++ : template <class T> T TCODList::peek() const
    C   : void * TCOD_list_peek(TCOD_list_t l)

Parameter | Description
--- | ---
l | In the C version, the list handler, returned by a constructor.

Example :

    C++ : TCODList<int> intList;
          intList.push(3); // intList contains 1 elements : 3
          int val = intList.peek(); // val == 3, inList contains 1 elements : 3
          intList.push(2); // intList contains 2 elements : 3, 2
          val = intList.peek(); // val == 2, inList contains 2 elements : 3, 2
    C   : TCOD_list_t intList = TCOD_list_new();
          TCOD_list_push(intList,(const void *)3);
          int val = (int)TCOD_list_peek(intList);
          TCOD_list_push(intList,(const void *)2);
          val = (int)TCOD_list_peek(intList);