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

Commit

Permalink
Laboratorio 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Laifsyn committed May 28, 2024
1 parent 23d8acd commit b52b1a7
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
82 changes: 82 additions & 0 deletions src/main/java/com/utp/clsEstructuraDatos/Estructuras/Cola.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.utp.clsEstructuraDatos.Estructuras;

public class Cola<T> {
public static void main(String[] args) {
Cola<Long> cola = new Cola<>(5);
cola.insertar(80l);
cola.insertar(568l);
cola.insertar(466651l);
cola.insertar(46512365123512312l);
cola.insertar(5484864856456553111l);
System.out.println(cola.toString());
cola.quitar_frente();
System.out.println(cola.toString());

}

// Posición en la que se puede extraer
int frente = 0;
// Posición en la que se puede insertar
int cola = 0;
int longitud = 0;
int capacidad;
final Object[] inner;

public Cola(int capacidad) {
this.capacidad = capacidad;
this.inner = new Object[capacidad];
}

boolean insertar(T elemento) {
if (is_full())
return false;
inner[cola] = elemento;
System.out.println((T) elemento);
cola++;
if (cola == capacidad)
cola = 0;

longitud++;
return true;
}

T quitar_frente() {
if (longitud == 0)
return null;
var frente = this.frente;
longitud--;
this.frente++;
if (this.frente == capacidad)
this.frente = 0;
@SuppressWarnings("unchecked")
var valor = (T) inner[frente];
inner[frente] = null;
return valor;
}

int espacio_libre() {
return capacidad - longitud;
}

boolean is_full() {
return !(longitud < capacidad);
}

boolean is_empty() {
return (longitud == 0);
}

public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[");
for (var item : inner) {
if (item == null)
sb.append("_, ");
else
sb.append(String.format("%s, ", item));
}
sb.delete(sb.length() - 2, sb.length());
sb.append("]");
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
import java.util.ArrayList;

import com.utp.clsEstructuraDatos.Estructuras.Pila;

class Num2Words{
public static String to_word(String input, String options){
return "Me llamaste";
}
}
public class Main {
public static void main(String[] args) {
System.out.println(Num2Words.to_word(null, null));;
App app = new App();
app.start();
}
Expand All @@ -33,11 +38,14 @@ void start() {
frame.setLayout(new GridBagLayout());
add_button_commands(frame);
GridBagConstraints c = new GridBagConstraints();

// Representación en vivo de la Pila
c.gridy = 2;
c.gridwidth = 8;
this.textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));
this.textArea.setEditable(false);
frame.add(this.textArea, c);

frame.setVisible(true);
}

Expand Down

0 comments on commit b52b1a7

Please sign in to comment.