Exemple #1
0
 void insertInternal(Node* nodePtr, double d)
 {
     if (d < nodePtr->Data)
     {
         if (nodePtr -> Left == NULL)
         {
             nodePtr -> Left = new Node(d);
         }
         else
         {
             insertInternal(nodePtr -> Left, d);
         }
     }
     
     if (d >= nodePtr->Data)
     {
         if (nodePtr -> Right == NULL)
         {
             nodePtr -> Right = new Node(d);
         }
         else
         {
             insertInternal(nodePtr -> Right, d);
         }
     }            
 }
Exemple #2
0
/**
 * Internal method to insert into a subtree.
 * x is the item to insert.
 * t is the node that roots the tree.
 * Set the new root.
 */
void
BinarySearchTree::insertInternal (Customer * x, BinaryNode * &t)
{
  if (t == NULL)
    t = new BinaryNode (x, NULL, NULL);
  else
    if (lessthan
        (const_cast < Customer * >(x), const_cast < Customer * >(t->element)))
      insertInternal (x, t->left);
    else
      if (lessthan
          (const_cast < Customer * >(t->element), const_cast < Customer * >(x)))
        insertInternal (x, t->right);
      else {
        throw InsertException (x);	// Duplicate;
      }
}
void String::insert(const LChar* charactersToInsert, unsigned lengthToInsert, unsigned position)
{
    if (position >= length()) {
        append(charactersToInsert, lengthToInsert);
        return;
    }
    ASSERT(m_impl);
    m_impl = insertInternal(m_impl.release(), charactersToInsert, lengthToInsert, position);
}
Exemple #4
0
 void insert(double d)
 {
    insertInternal(Root, d);    
 }
Exemple #5
0
/**
 * Insert x into the tree;
 */
void
BinarySearchTree::insert (Customer * x)
{
  insertInternal (x, root);
}