Initial commit

This commit is contained in:
Chris Cromer
2016-06-20 13:25:01 -04:00
commit a41abff9b0
66 changed files with 4205 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
public int buscar(int valor) {
for (int i = 0; i < array.length; i++) {
if (array[i] != 0 && array[i] == valor) {
// Se encontró
return i;
}
}
// No se encontró
return -1;
}

View File

@@ -0,0 +1,18 @@
public boolean eliminar(int valor) {
boolean borrado = false;
for (int i = 0; i < array.length; i++) {
if (array[i] != 0 && array[i] == valor) {
// Eliminar el valor
array[i] = 0;
borrado=true;
for (int j = i; j < array.length; j++) {
if (j != array.length - 1) {
// Correr la array hacia arriba
array[j] = array[j + 1];
}
}
array[array.length-1] = 0;
}
}
return borrado;
}

View File

@@ -0,0 +1,13 @@
public boolean insertar(int valor) {
for (int i = 0; i < array.length; i++) {
if (array[i] == 0) {
array[i] = valor;
return true;
}
else if (array[i] == valor) {
// Ya existe el valor en el array
return false;
}
}
return false;
}

View File

@@ -0,0 +1,10 @@
public int buscar(int valor) {
for (int i = 0; i < array.length; i++) {
if (array[i] != 0 && array[i] == valor) {
// Se encontró
return i;
}
}
// No se encontró
return -1;
}

View File

@@ -0,0 +1,12 @@
public boolean eliminar(int valor) {
boolean borrado = false;
for (int i = 0; i < array.length; i++) {
if (array[i] != 0 && array[i] == valor) {
// Eliminar el valor
array[i] = 0;
borrado=true;
break;
}
}
return borrado;
}

View File

@@ -0,0 +1,13 @@
public boolean insertar(int valor) {
for (int i = 0; i < array.length; i++) {
if (array[i] == 0) {
array[i] = valor;
return true;
}
else if (array[i] == valor) {
// Ya existe el valor en el array
return false;
}
}
return false;
}

View File

@@ -0,0 +1,13 @@
public void burbuja() {
for (int i = elementos - 1; i > 1; i--) {
for(j = 0; in < i; j++) {
// Si están fuera del orden
if (array[j] > array[j+1]) {
// Intercambiar valores
int temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
}

View File

@@ -0,0 +1,4 @@
public int peek() {
// Devolver el valor en el primer indice
return this.pila[primer];
}

View File

@@ -0,0 +1,6 @@
public void pop() {
// Borrar el valor que está al prinicipio.
this.pila[primer] = 0;
// Cambiar el primer nivel de la cola.
primer++;
}

View File

@@ -0,0 +1,6 @@
public void push(int valor) {
// Sumar el final.
final++;
// Insertar el valor
this.pila[final] = valor;
}

View File

@@ -0,0 +1,14 @@
public void insercion() {
for (int i = 1; i < elementos; i++) {
// Guardar el elemento en un variable temporario.
int temp = array[i];
int j = i;
// Mover los valores hasta que hay una mas pequeño.
while (j > 0 && array[j-1] >= temp) {
array[j] = array[j-1];
--j;
}
// Poner el valor temporario despues de los valores mas pequeños.
array[j] = temp;
}
}

View File

@@ -0,0 +1,4 @@
public int peek() {
// Devolver el valor encima
return this.pila[encima];
}

View File

@@ -0,0 +1,6 @@
public void pop() {
// Borrar el valor que está encima.
this.pila[encima] = 0;
// Restar el nivel de la pila.
encima--;
}

View File

@@ -0,0 +1,6 @@
public void push(int valor) {
// Sumar el nivel de la pila
encima++;
// Insertar el valor
this.pila[encima] = valor;
}

View File

@@ -0,0 +1,13 @@
public void seleccion() {
for (int i = 0; i < elementos - 1; i++) {
int minimo = i;
for (int j = i + 1; j < elementos; j++) {
if (array[j] < array[minimo]) {
minimo = j;
}
}
int temp = array[i];
array[i] = array[minimo];
array[minimo] = temp;
}
}