/*------------------------------------------------------------------*/ /* testlist.c (Version 4: Iterator) */ /*------------------------------------------------------------------*/ #include "list.h" #include #include #include int main(int argc, char *argv[]) { List_T oList; ListIter_T oListIter1; ListIter_T oListIter2; oList = List_new(); List_addFirst(oList, "Ruth"); List_addFirst(oList, "Gehrig"); List_addLast(oList, "Mantle"); List_addLast(oList, "Jeter"); oListIter1 = ListIter_new(oList); ListIter_selectFirst(oListIter1); while (ListIter_selectionValid(oListIter1)) { printf("%s\n", (char*)ListIter_selectedItem(oListIter1)); ListIter_selectNext(oListIter1); } ListIter_free(oListIter1); oListIter2 = ListIter_new(oList); ListIter_selectLast(oListIter2); while (ListIter_selectionValid(oListIter2)) { printf("%s\n", (char*)ListIter_selectedItem(oListIter2)); ListIter_selectPrev(oListIter2); } ListIter_free(oListIter2); List_free(oList); return 0; } /* Output: Gehrig Ruth Mantle Jeter Jeter Mantle Ruth Gehrig */