Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
pilas
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilsC8 committed Jun 6, 2024
1 parent b5edcb5 commit 33b171c
Show file tree
Hide file tree
Showing 6 changed files with 334 additions and 476 deletions.
82 changes: 0 additions & 82 deletions src/main/java/com/utp/clsEstructuraDatos/pry3/DrawTable.java
Original file line number Diff line number Diff line change
@@ -1,82 +0,0 @@
package com.utp.clsEstructuraDatos.pry3;

import java.util.ArrayList;

public class DrawTable {
private int columnas = 0;
private ArrayList<String[]> table = null;

public DrawTable() {
}

public void insertar_fila(String[] row) {
if (this.columnas == 0) {
this.columnas = row.length;
}
// Todas las filas tienen que tener la misma cantidad columna
if (this.columnas != row.length) {
throw new IllegalArgumentException("La fila no tiene la misma cantidad de columnas que las anteriores");
}
this.table.add(row);
}

public String toString() {
StringBuilder sb = new StringBuilder();
throw new UnsupportedOperationException("asdasdsa");
// for (String[] row : this.table) {
// for (String cell : row) {
// sb.append(cell);
// sb.append(" ");
// }
// sb.append("\n");
// }
// return sb.toString();
}

/*
* |__|| asdfa||c|
* ------------------------
* | 1||23jgadsdsavghgh||3|
* | 4|| 5||6|
*/
public static void main(String[] args) {

String[][] mi_tabla = new String[][] { { "____", "asdfa", "c" }, { "1", "23jgadsdsavghgh", "3" },
{ "4", "5", "6" } };
ArrayList<Integer> ancho_columna = new ArrayList<>();
System.err.println("Antes : " + ancho_columna.toString());
for (String celda : mi_tabla[0]) {
ancho_columna.add(celda.length());
}

System.out.println("Primera vuelta te va a dar: " + ancho_columna.toString());
for (String[] fila : mi_tabla) {
for (int i = 0; i < fila.length; i++) {
if (ancho_columna.get(i) < fila[i].length()) {
ancho_columna.set(i, fila[i].length());
}
}
}

System.out.println();
System.err.println("Despues: " + ancho_columna.toString());

System.out.println("Tabla de verdad");
for (int j = 0; j < mi_tabla.length; j++) {
for (int i = 0; i < mi_tabla[j].length; i++) {
// Por defecto
System.out.print(String.format("|%" + ancho_columna.get(i) + "s|", mi_tabla[j][i]));
}
System.out.println();

if (j == 0) {
for (int k = 0; k < mi_tabla[0].length; k++) {
System.out.print("|" + "=".repeat(ancho_columna.get(k)) + "|");
}
System.out.println();
}
}
System.exit(0);
}
}

188 changes: 0 additions & 188 deletions src/main/java/com/utp/clsHerramientas/pry1/App.java

This file was deleted.

112 changes: 112 additions & 0 deletions src/main/java/com/utp/clsHerramientas/pry1/Pila.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.utp.clsHerramientas.pry1;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Optional;

import com.utp.utils.Utils;
import com.utp.utils.Cli;
import java.util.Scanner;
public class Pila {
private static final int MAX_CONTE = 6;
private static int[] pila = new int[MAX_CONTE];
private static int tope = -1;

public static boolean pilaVacia() {
return tope == -1;
}

public static boolean pilaLlena() {
return tope == MAX_CONTE - 1;
}

public static void insertaElemento(int elemento) {
if (pilaLlena()) {
System.out.println("Overflow");
} else {
pila[++tope] = elemento;
System.out.println("Elemento insertado.");
}
}

public static void eliminarElemento() {
if (pilaVacia()) {
System.out.println("Underflow");
} else {
System.out.println("Elemento " + pila[tope--] + " eliminado correctamente.");
}
}

public static void elementoCima() {
if (pilaVacia()) {
System.out.println("Pila sin elementos");
} else {
System.out.println("El elemento en la cima de la pila es: " + pila[tope]);
}
}

public static void mostrarContenido() {
if (pilaVacia()) {
System.out.println("Pila vacía.");
} else {
System.out.print("Contenido de la pila: ");
for (int i = 0; i <= tope; i++) {
System.out.print(pila[i] + " ");
}
System.out.println();
}
}

public static void menu() {
Scanner sc = new Scanner(System.in);
int elemento, opcion;
do {
System.out.println("\nMenú de opciones:");
System.out.println("1. Insertar elementos en la pila.");
System.out.println("2. Eliminar elementos de la pila.");
System.out.println("3. Mostrar elemento en la cima de la pila.");
System.out.println("4. Mostrar contenido de la pila.");
System.out.println("5. Salir.");
System.out.print("\nIngrese una opción: ");
opcion = sc.nextInt();

switch (opcion) {
case 1:
mostrarContenido();
System.out.print("Ingrese el elemento para la pila: ");
elemento = sc.nextInt();
insertaElemento(elemento);
mostrarContenido();
break;

case 2:
mostrarContenido();
eliminarElemento();
mostrarContenido();
break;

case 3:
elementoCima();
break;

case 4:
mostrarContenido();
break;

case 5:
System.out.println("Deteniendo el programa.");
break;

default:
System.out.println("Opción inválida. Ingrese una válida.");
break;
}
} while (opcion != 5);

sc.close();
}

public static void main(String[] args) {
menu();
}
}
Loading

0 comments on commit 33b171c

Please sign in to comment.