ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Programacion Java Ejemplos COLAS


Enviado por   •  22 de Junio de 2020  •  Prácticas o problemas  •  10.684 Palabras (43 Páginas)  •  181 Visitas

Página 1 de 43

CÓDIGOS DE PROGRAMACIÓN EN NETBEANS

EJEMPLOS DE COLAS

EJEMPLO 1

Código Fuente

Insertar

public class Insertar {

static class Nodo {

int dato;

Nodo sig;

}

public static void main(String[] args) {

int n;

Nodo top = null;

Nodo ultimo = null;

System.out.println("Ingrese el número de elementos de la cola");

Scanner leer= new Scanner(System.in);

n= leer.nextInt();

System.out.println("COLA");

for (int i = 1; i <= n; i++) {

Nodo temp = new Nodo();

temp.dato = i;

temp.sig = null;

if (top == null) {

top = temp;

} else {

ultimo.sig = temp;

}

ultimo = temp;

}

Nodo temp = top;

while (temp != null) {

System.out.println(temp.dato);

temp = temp.sig;

}

}

}

MODIFICAR

public class Modificar {

static class Nodo {

int dato;

Nodo sig;

}

public static void main(String[] args) {

int n;

int buscar;

int modificar;

Nodo top = null;

Nodo ultimo = null;

Nodo colat = null;

Nodo ultimot = null;

Scanner leer= new Scanner(System.in);

System.out.println("Ingrese el número de elementos de la cola");

n= leer.nextInt();

System.out.println("COLA");

for (int i = 1; i <= n; i++) {

Nodo temp = new Nodo();

temp.dato = i;

temp.sig = null;

if (top == null) {

top = temp;

} else {

ultimo.sig = temp;

}

ultimo = temp;

System.out.println(temp.dato);

}

Nodo temp = top;

System.out.println("\n Ingrese el numero que desea modificar");

buscar = leer.nextInt();

while (temp.dato != buscar) {

Nodo temp1 = new Nodo();

temp1.dato = temp.dato;

temp1.sig = null;

if (colat == null) {

colat = temp1;

} else {

ultimot.sig = temp1;

}

ultimot = temp1;

top = top.sig;

temp = top;

}

System.out.println("Ingrese el nuevo dato");

modificar = leer.nextInt();

top.dato = modificar;

ultimot.sig = top;

top = colat;

colat = null;

temp = top;

System.out.println("\n COLA ACTUAL");

while (temp != null) {

System.out.println(temp.dato);

temp = temp.sig;

}

}

}

...

Descargar como (para miembros actualizados)  txt (24.7 Kb)   pdf (68.2 Kb)   docx (24.8 Kb)  
Leer 42 páginas más »
Disponible sólo en Clubensayos.com