/** * Time Complexity::O(log n),n=number of elements present.<br> * Memory::O(log n),for traversing stack is formed<br> * You can optimize it using user_defined stack. */ void insertTree(UraInstantiator uraI, BaseNode p, BaseNode root) { if ((tmp2.nodeIndex < p.nodeIndex)) { if (p.left != null) { insertTree(uraI, p.left, p); } else { p.left = tmp2; tmp2 = null; } if ((insertFlag == true) && (vMFlag == true)) { p.nodeIndex += 1l; p.vMFactor += 1l; } } else { long tmpnode = tmp2.nodeIndex; tmpnode -= p.vMFactor; if (tmp2.nodeIndex == p.nodeIndex) { insertFlag = true; ClientData temp = p.data; p.data = tmp2.data; tmp2.data = temp; p.vMFactor += 1l; } tmp2.nodeIndex = tmpnode; if (p.right != null) { insertTree(uraI, p.right, p); } else { p.right = tmp2; tmp2 = null; } vMFlag = true; } uraI.getBaseStructure().checkForUnbalancing(uraI, p, root); }
void insert1(UraInstantiator uraI, long node, ClientData data, BaseNode p) { if (node >= 0l) { insertFlag = false; vMFlag = false; tmp2 = new BaseNode(); tmp2.nodeIndex = node; tmp2.data = data; if (rootTREE == null) { rootTREE = new BaseNode(); rootTREE.left = tmp2; } else { insertTree(uraI, rootTREE.left, rootTREE); } } else System.out.println(" NEGATIVE INDEX ARE NOT ACCEPTED"); }