code: public Node replaceNode(int index, Node newNode)
      {
          if (index == 0)
          {
              return newNode;
          }
  
          int leftNodes = left.countNodes();
          if (index <= leftNodes)
          {
              return newInstance(left.replaceNode(index - 1, newNode), right);
          }
          else
          {
              return newInstance(left, right.replaceNode(index - leftNodes - 1, newNode));
          }
      }
docs: {@inheritDoc}