diff --git a/src/main/java/com/utp/clsEstructuraDatos/Estructuras/linked_list/LEColaCircular.java b/src/main/java/com/utp/clsEstructuraDatos/Estructuras/linked_list/LEColaCircular.java index 15de4dc..9b5aaa8 100644 --- a/src/main/java/com/utp/clsEstructuraDatos/Estructuras/linked_list/LEColaCircular.java +++ b/src/main/java/com/utp/clsEstructuraDatos/Estructuras/linked_list/LEColaCircular.java @@ -28,4 +28,8 @@ public T peek() { return null; } + public LinkedList extricate() { + return inner; + } + } diff --git a/src/main/java/com/utp/clsEstructuraDatos/Estructuras/linked_list/LEColaLineal.java b/src/main/java/com/utp/clsEstructuraDatos/Estructuras/linked_list/LEColaLineal.java index 3ee3425..8febb49 100644 --- a/src/main/java/com/utp/clsEstructuraDatos/Estructuras/linked_list/LEColaLineal.java +++ b/src/main/java/com/utp/clsEstructuraDatos/Estructuras/linked_list/LEColaLineal.java @@ -29,4 +29,8 @@ public T peek() { } return null; } + + public LinkedList extricate() { + return inner; + } } diff --git a/src/main/java/com/utp/clsEstructuraDatos/Estructuras/linked_list/LEPila.java b/src/main/java/com/utp/clsEstructuraDatos/Estructuras/linked_list/LEPila.java index 61e4cba..4937d58 100644 --- a/src/main/java/com/utp/clsEstructuraDatos/Estructuras/linked_list/LEPila.java +++ b/src/main/java/com/utp/clsEstructuraDatos/Estructuras/linked_list/LEPila.java @@ -57,4 +57,7 @@ public boolean isFull() { return false; } + public LinkedList extricate() { + return inner; + } } diff --git a/src/main/java/com/utp/clsEstructuraDatos/laboratorio_4/Main.java b/src/main/java/com/utp/clsEstructuraDatos/laboratorio_4/Main.java new file mode 100644 index 0000000..22aea35 --- /dev/null +++ b/src/main/java/com/utp/clsEstructuraDatos/laboratorio_4/Main.java @@ -0,0 +1,169 @@ +package com.utp.clsEstructuraDatos.laboratorio_4; + +import java.util.Optional; + +import com.utp.clsEstructuraDatos.Estructuras.linked_list.LEColaCircular; +import com.utp.clsEstructuraDatos.Estructuras.linked_list.LEColaLineal; +import com.utp.clsEstructuraDatos.Estructuras.linked_list.LEPila; +import com.utp.clsEstructuraDatos.Estructuras.linked_list.LinkedList; + +public class Main { + +} + +class App { + static final String LABORATORIO = "Laboratorio 4"; + Optional> collection; + + void new_collection() {} + +} + +sealed interface AppCollection { + // @formatter:off + void insert(T element); + Optional pop(); + Optional peek(); + boolean isEmpty(); + boolean isFull(); + void clear(); + int len(); + default AppCollection extend_from(AppCollection source){ + switch (source) { + case Stack(var stack) -> { + var element = stack.extricate + this.insert() + } + case Queue(var queue) -> { + for (int i = 0; i < list.len(); i++) { + queue.insert(list.get(i).get()); + } + return new Queue<>(queue); + } + case CircularQueue(var circular_queue) -> { + for (int i = 0; i < list.len(); i++) { + circular_queue.insert(list.get(i).get()); + } + return new CircularQueue<>(circular_queue); + } + } + } + // @formatter:on + + public record Stack(LEPila pila) implements AppCollection { + + @Override + public void insert(T element) { + pila.push(element); + } + + @Override + public Optional pop() { + return Optional.ofNullable(pila.pop()); + } + + @Override + public Optional peek() { + return Optional.ofNullable(pila.peek_top()); + } + + @Override + public boolean isEmpty() { + return pila.len() == 0; + } + + @Override + public boolean isFull() { + // Since LEPila is backed by a LinkedList, it's never full. + return false; + } + + @Override + public void clear() { + pila.clear(); + } + + @Override + public int len() { + return pila.len(); + } + } + + public record Queue(LEColaLineal lineal_queue) implements AppCollection { + + @Override + public void insert(T element) { + lineal_queue.insert(element); + } + + @Override + public Optional pop() { + return Optional.ofNullable(lineal_queue.remove()); + } + + @Override + public Optional peek() { + return Optional.ofNullable(lineal_queue.peek()); + } + + @Override + public boolean isEmpty() { + return lineal_queue.len() == 0; + } + + @Override + public boolean isFull() { + // Since LEColaLineal is backed by a LinkedList, it's never full. + return false; + } + + @Override + public void clear() { + lineal_queue.clear(); + } + + @Override + public int len() { + return lineal_queue.len(); + } + } + + public record CircularQueue(LEColaCircular looped_queue) implements AppCollection { + + @Override + public void insert(T element) { + looped_queue.insert(element); + } + + @Override + public Optional pop() { + return Optional.ofNullable(looped_queue.remove()); + } + + @Override + public Optional peek() { + return Optional.ofNullable(looped_queue.peek()); + } + + @Override + public boolean isEmpty() { + return looped_queue.len() == 0; + } + + @Override + public boolean isFull() { + // Since LEColaCircular is backed by a LinkedList, it's never full. + return false; + } + + @Override + public void clear() { + looped_queue.clear(); + } + + @Override + public int len() { + return looped_queue.len(); + } + } +}