From eadc16f24146752097fdda7392bb9b0ed76ee9f2 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Thu, 9 Apr 2015 14:29:50 +0000 Subject: [PATCH] AVL Iterator. FossilOrigin-Name: 8232f083c22ebc5207a46f412f7ef272b86233d41d167d7c5a09540a1a30429c --- src/capwap/avliter_next.c | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/capwap/avliter_next.c diff --git a/src/capwap/avliter_next.c b/src/capwap/avliter_next.c new file mode 100644 index 00000000..e6f48abc --- /dev/null +++ b/src/capwap/avliter_next.c @@ -0,0 +1,43 @@ +#include "avltree.h" + + +void * avliter_next(avliter_t *i) +{ + + while ( i->stack_ptr) { + i->stack_ptr--; + i->cur=i->stack[i->stack_ptr]; + + if (!i->cur) + continue; + + if ((i->stack_ptr)&1) { + return i->cur->data; + } + break; + + } + + + if (!i->cur){ + return NULL; + } + + while(i->cur->left) { + /* push right branch */ + i->stack[i->stack_ptr++]=i->cur->right; + + /* push node */ + i->stack[i->stack_ptr++]=i->cur; + + + i->cur=i->cur->left; + + } + + i->stack[i->stack_ptr++]=i->cur->right; + + return i->cur->data; +} + +