package tipo_pila;
import java.util.Scanner;
public class Array_Pila {
int vectorPila[];
int tope;
public Array_Pila(int tam) {
vectorPila = new int[tam];
tope = -1;
}
public int getTope() {
return tope;
}
public void setTope(int tope) {
this.tope = tope;
}
public boolean vacio() {
return getTope() == -1;
}
public boolean lleno() {
if (getTope() == vectorPila.length - 1)
return true;
else
return false;
}
public void insertar(int dato) {
setTope(getTope() + 1);
vectorPila[getTope()] = dato;
}
public void eliminar(int buscar) {
int pilaAux[]=new int[vectorPila.length];
int topeAux=-1;
while(!vacio()){
// SI ES EL VALOR ENCONTRADO ESTA EN LA UBICACION DEL TOPE, SOLO ELIMINAR_TOP
if(vectorPila[getTope()]==buscar){
Eliminar_Top();
break;
}else{
// SI NO LO ES LO METE EN LA PILA AUXILIAR
topeAux++;
pilaAux[topeAux]=vectorPila[getTope()];
Eliminar_Top();
}
}
// LO REGRESA A LA PILA ORGINAL
while(topeAux>=0) {
insertar(pilaAux[topeAux]);
topeAux--;
}
}
public void Modify(int buscar, int modificar) {
for (int indice = tope; indice >= 0; indice--) {
if (vectorPila[indice] == buscar) {
vectorPila[indice] = modificar;
}
}
}
public void Eliminar_Top() {
setTope(getTope() - 1);
}
public void imprimir_Pila() {
for (int i = getTope(); i >= 0; i--) {
System.out.println("Data de la pila: " + vectorPila[i]);
}
}
}
public void Modify(int buscar, int modificar) {
for (int indice = tope; indice >= 0; indice--) {
if (vectorPila[indice] == buscar) {
vectorPila[indice] = modificar;
}
}
}
public void Eliminar_Top() {
setTope(getTope() - 1);
}
public void imprimir_Pila() {
for (int i = getTope(); i >= 0; i--) {
System.out.println("Data de la pila: " + vectorPila[i]);
}
}
}
Comentarios sobre la versión: 1.0 (0)
No hay comentarios