< index < 8. All purposes container < 8.4 Basic stack operations |
===================================== | > 8.6 Deleting a list |
C++ : template <class T> T * TCODList::begin() const template <class T> T * TCODList::end() const C : void ** TCOD_list_begin(TCOD_list_t l) void ** TCOD_list_end(TCOD_list_t l)
Parameter | Description |
---|---|
l | In the C version, the list handler, returned by a constructor. |
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 for ( int * iterator = intList.begin(); iterator != intList.end(); iterator ++ ) { int currentValue=*iterator; printf("value : %d\n", currentValue ); } C : TCOD_list_t intList = TCOD_list_new(); TCOD_list_push(intList,(const void *)5); TCOD_list_push(intList,(const void *)2); for ( int * iterator = (int *)TCOD_list_begin(intList); iterator != (int *)TCOD_list_end(intList); iterator ++ ) { int currentValue=*iterator; printf("value : %d\n", currentValue ); }
C++ : template <class T> T *TCODList::remove(T *iterator) template <class T> T *TCODList::removeFast(T *iterator) C : void **TCOD_list_remove_iterator(TCOD_list_t l, void **iterator) void **TCOD_list_remove_iterator_fast(TCOD_list_t l, void **iterator)
Parameter | Description |
---|---|
iterator | The list iterator. |
l | In the C version, the list handler, returned by a constructor. |
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 intList.push(3); // the list contains 3 elements : 5,2,3 for ( int * iterator = intList.begin(); iterator != intList.end(); iterator ++ ) { int currentValue=*iterator; if ( currentValue == 2 ) { // remove this value from the list and keep iterating on next element (value == 3) iterator = intList.remove(iterator); } printf("value : %d\n", currentValue ); // all 3 values will be printed : 5,2,3 } // now the list contains only two elements : 5,3 C : TCOD_list_t intList = TCOD_list_new(); TCOD_list_push(intList,(const void *)5); TCOD_list_push(intList,(const void *)2); TCOD_list_push(intList,(const void *)3); for ( int * iterator = (int *)TCOD_list_begin(intList); iterator != (int *)TCOD_list_end(intList); iterator ++ ) { int currentValue=*iterator; if ( currentValue == 2 ) { iterator = (int *)TCOD_list_remove_iterator(intList,(void **)iterator); } printf("value : %d\n", currentValue ); }