Codigo de un arbol en java

Páginas: 2 (337 palabras) Publicado: 28 de abril de 2011
import java.io.*;

class TreeNode {
String word; // Word being stored.
int count = 1; // Count of words seen in text.
TreeNode left; // Leftsubtree reference.
TreeNode right; // Right subtree reference.

public TreeNode (String word) {
this.word = word;
left = right = null;
}public void insert (String word) {
int status = this.word.compareTo (word);

if (status > 0) { // word argument precedes current word

// Ifleft-most leaf node reached, then insert new node as
// its left-most leaf node. Otherwise, keep searching left.
if (left == null)left = new TreeNode (word);
else
left.insert (word);
}
else
if (status < 0) { // word argument followscurrent word

// If right-most leaf node reached, then insert new node as
// its right-most leaf node. Otherwise, keep searching right.if (right == null)
right = new TreeNode (word);
else
right.insert (word);
}
elsethis.count++;
}
}
class WC {
public static void main (String [] args) throws IOException {
int ch;

TreeNode root = null;// Read each character from standard input until a letter
// is read. This letter indicates the start of a word.

while ((ch = System.in.read ()) != -1) {// If character is a letter then start of word detected.

if (Character.isLetter ((char) ch)) {
// Create StringBuffer object to hold word letters....
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Arboles en java
  • arboles en java
  • Arboles Java
  • Java arboles
  • Arboles java
  • Arboles
  • Codigos de java
  • Codigos De Java

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS