AVL Iterator.
FossilOrigin-Name: 8232f083c22ebc5207a46f412f7ef272b86233d41d167d7c5a09540a1a30429c
This commit is contained in:
parent
f08bdbd48a
commit
eadc16f241
43
src/capwap/avliter_next.c
Normal file
43
src/capwap/avliter_next.c
Normal file
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user