make tree operations generic on iterator type