Cita:
Iniciado por _Ruben_ Pues si, tiene toda la pinta de ser un bucle infinito, pero si no muestras el código nadie podrá ayudarte.
Gracias, si tienes razon este es mi codigo si consigues ver el fallo dimelo pliz
import java.io.IOException;
import java.io.*;
class NInternal extends Node {
Node[] next;
}
class NList extends Node {
String w;
NList[] next = new NList[10];
}
class Node {
char c;
NInternal[] i = new NInternal[10];
NList e = new NList();
}
class Arboljd {
static public char getChar() throws IOException {
char c = (char) System.in.read();
input();
return c;
}
static public void input() throws IOException {
while ((char) System.in.read() != '\n')
;
}
static public int initNode(Node n, char l) throws IOException {
// Inicializar el nodo a insertar
n.e = null;
n.c = l;
return 0;
}
static public int insertNode(char l, int r, Node root) throws IOException {
// Inicializar el nodo a insertar
Node newNode = new Node();
if (initNode(newNode, l) != 0) {
System.out.println("Fallo al inicializar el Nodo\n");
} else {
// En caso de que sea el primer nodo a insertar.
if (root == null) {
System.out.println("Se va a insertar el nodo raiz \n");
root = newNode;
} else { // Cualquier otro nodo despues del raiz.
}
}
return r;
}
static public int insertWord(Node n, String l) {
String sAux = l;
Node nAux = n;
char cAux;
for(int i = 0; i < sAux.length(); i++) {
cAux = sAux.charAt(0);
switch (cAux) {
case 'a' | 'A':
nAux = nAux.i[0];
break;
case 'b' | 'B':
nAux = nAux.i[1];
break;
case 'c' | 'C':
nAux = nAux.i[2];
break;
case 'd'|'D' :
nAux = nAux.i[3];
break;
case 'e'|'E' :
nAux = nAux.i[4];
break;
case 'f'|'F' :
nAux = nAux.i[5];
break;
case 'g'|'G' :
nAux = nAux.i[6];
break;
case 'h'|'H' :
nAux = nAux.i[7];
break;
case 'i'|'I' :
nAux = nAux.i[8];
break;
case 'j'|'J' :
nAux = nAux.i[9];
break;
case 'k'|'K' :
nAux = nAux.i[10];
break;
case 'l'|'L' :
nAux = nAux.i[11];
break;
case 'm'|'M' :
nAux = nAux.i[12];
break;
case 'n'|'N' :
nAux = nAux.i[13];
break;
case 'o'|'O' :
nAux = nAux.i[14];
break;
case 'p'|'P' :
nAux = nAux.i[15];
break;
case 'q'|'Q' :
nAux = nAux.i[16];
break;
case 'r'|'R' :
nAux = nAux.i[17];
break;
case 's'|'S' :
nAux = nAux.i[18];
break;
case 't'|'T' :
nAux = nAux.i[19];
break;
case 'u'|'U' :
nAux = nAux.i[20];
break;
case 'v'|'V' :
nAux = nAux.i[21];
break;
case 'w'|'W' :
nAux = nAux.i[22];
break;
case 'x'|'X' :
nAux = nAux.i[23];
break;
case 'y'|'Y' :
nAux = nAux.i[24];
break;
case 'z'|'Z' :
nAux = nAux.i[25];
break;
default:
break;
}
}
for(int i=0;i<10;i++){
if(nAux.e.next[i] == null) nAux.e.w = l;
}
return 0;
}
public static void main(String[] args) throws IOException {
char res;
Node root = null;
String s = "";
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(input);
do {
System.out.println("Inserte una palabra y pulse ENTER");
try {
s = reader.readLine();
} catch (Exception e) {
}
System.out.println("Escribiste: " + s + "\n");
int n[];
n = new int[26];
int tam = s.length();
int index = 0;
int max = 0;
char l;
do {
l = s.charAt(index);
switch (l) {
case 'a':
n[0]++;
if (max < 0) {
max = 0;
}
break;
case 'b':
n[1]++;
if (max < 1) {
max = 1;
}
break;
case 'c':
n[2]++;
if (max < 2) {
max = 2;
}
break;
case 'd':
n[3]++;
if (max < 3) {
max = 3;
}
break;
case 'e':
n[4]++;
if (max < 4) {
max = 4;
}
break;
case 'f':
n[5]++;
if (max < 5) {
max = 5;
}
break;
case 'g':
n[6]++;
if (max < 6) {
max = 6;
}
break;
case 'h':
n[7]++;
if (max < 7) {
max = 7;
}
break;
case 'i':
n[8]++;
if (max < 8) {
max = 8;
}
break;
case 'j':
n[9]++;
if (max < 9) {
max = 9;
}
break;
case 'k':
n[10]++;
if (max < 10) {
max = 10;
}
break;
case 'l':
n[11]++;
if (max < 11) {
max = 11;
}
break;
case 'm':
n[12]++;
if (max < 12) {
max = 12;
}
break;
case 'n':
n[13]++;
if (max < 13) {
max = 13;
}
break;
case 'o':
n[14]++;
if (max < 14) {
max = 14;
}
break;
case 'p':
n[15]++;
if (max < 15) {
max = 15;
}
break;
case 'q':
n[16]++;
if (max < 16) {
max = 16;
}
break;
case 'r':
n[17]++;
if (max < 17) {
max = 17;
}
break;
case 's':
n[18]++;
if (max < 18) {
max = 18;
}
break;
case 't':
n[19]++;
if (max < 19) {
max = 19;
}
break;
case 'u':
n[20]++;
if (max < 20) {
max = 20;
}
break;
case 'v':
n[21]++;
if (max < 21) {
max = 21;
}
break;
case 'w':
n[22]++;
if (max < 22) {
max = 22;
}
break;
case 'x':
n[23]++;
if (max < 23) {
max = 23;
}
break;
case 'y':
n[24]++;
if (max < 24) {
max = 24;
}
break;
case 'z':
n[25]++;
if (max < 25) {
max = 25;
}
break;
default:
break;
}
index++;
} while (index < tam);
System.out.println("La ultima letra es la numero: " + max);
for (index = 0; index <= max; index++) {
if (insertNode((char) n[index], index, root) != 0) {
System.out.println("Se inserto el caracter " + index
+ " con: " + n[index] + " repeticiones");
}
if (n[index] != 0) {
System.out.println("Cantidad de letras " + index
+ " en la frase es:" + n[index]);
}
}
insertWord(root, s);
// exter[max] = max;
System.out.println("Quiere insertar otra palabra? S/N");
res = getChar();
} while (res != ('n'));
}
}