Nice TWiki > Doc > BinarySearchTreeExample (r1.1 vs. r1.2) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
 <<O>>  Difference Topic BinarySearchTreeExample (r1.2 - 11 Apr 2005 - TWikiGuest)
Added:
>
>

public ?U getValue(?IntTreeNode node, T key); getValue(null, key) = null;

Changed:
<
<

?IntTreeNode theleft = left;

>
>

let theleft = left;

Changed:
<
<

theleft = new IntTreeNode? (m_key: key, m_value: value);

>
>

left = new IntTreeNode? (m_key: key, m_value: value);

Added:
>
>

left = theleft;

Changed:
<
<

?IntTreeNode theright = right;

>
>

let theright = right;

Changed:
<
<

theright = new IntTreeNode? (m_key: key, m_value: value);

>
>

right = new IntTreeNode? (m_key: key, m_value: value);

Added:
>
>

right = theright;

Changed:
<
<

public ?U getValue(T key) {

>
>

override ?U getValue(T key) {

Changed:
<
<

?IntTreeNode myleft = left; return myleft != null ? myleft.getValue(key) : null;

>
>

return left.getValue(key);

Changed:
<
<

?IntTreeNode myright = right; return myright != null ? myright.getValue(key) : null;

>
>

return right.getValue(key);

Changed:
<
<

?IntTreeNode mycontent = content;

>
>

let mycontent = content;

Changed:
<
<

mycontent = new IntTreeNode? (m_key: key, m_value: value);

>
>

content = new IntTreeNode? (m_key: key, m_value: value);

Added:
>
>

content = mycontent;

Changed:
<
<

?IntTreeNode mycontent = content; return mycontent != null ? mycontent.getValue(key) : null;

>
>

return content.getValue(key);


 <<O>>  Difference Topic BinarySearchTreeExample (r1.1 - 11 Apr 2005 - TWikiGuest)
Added:
>
>

%META:TOPICINFO{author="TWikiGuest" date="1113237420" format="1.0" version="1.1"}% %META:TOPICPARENT{name="CodeExamples"}%

<Comparable T,U>
class IntTreeNode <T,U> {
  private !T m_key;
  private U m_value;
  private ?IntTreeNode<T,U> left = null;
  private ?IntTreeNode<T,U> right = null;

  public void add (!T key, U value) {
    if (key == m_key)
    { 
      m_value = value;
    }
    else if (key < m_key)
    { 
      ?IntTreeNode<T,U> theleft = left;
      if (theleft == null) {
        theleft = new IntTreeNode (m_key: key, m_value: value);
      } else {
        theleft.add (key, value);
      }
    }
    else
    { 
      ?IntTreeNode<T,U> theright = right;
      if (theright == null) {
        theright = new IntTreeNode (m_key: key, m_value: value);
      } else {
        theright.add (key, value);
      }
    }
  }

  public ?U getValue(T key) {
    if (key == m_key) {
      return m_value;
    } else if (key < m_key) {
      ?IntTreeNode<T,U> myleft = left;
      return myleft != null ? myleft.getValue(key) : null;
    } else {
      ?IntTreeNode<T,U> myright = right;
      return myright != null ? myright.getValue(key) : null;
    }
  }
}

<Comparable T,U>
class IntTree <T,U> {
  ?IntTreeNode<T,U> content = null;

  public void add (!T key, !U value) {
    ?IntTreeNode<T,U> mycontent = content;
    if (mycontent == null) {
      mycontent = new IntTreeNode (m_key: key, m_value: value);
    } else {
      mycontent.add (key, value);
    }
  }

  public ?U getValue(!T key)
  {
    ?IntTreeNode<T,U> mycontent = content;
    return mycontent != null ? mycontent.getValue(key) : null;
  }
}

-- Raboof - 11 Apr 2005


Topic BinarySearchTreeExample . { View | Diffs | r1.2 | > | r1.1 | More }
Revision r1.1 - 11 Apr 2005 - 16:37 GMT - TWikiGuest
Revision r1.2 - 11 Apr 2005 - 18:04 GMT - TWikiGuest
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.