This repository has been archived by the owner on Aug 9, 2024. It is now read-only.
generated from microsoft/vscode-remote-try-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,8 @@ public T peek() { | |
return null; | ||
} | ||
|
||
public LinkedList<T> extricate() { | ||
return inner; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,8 @@ public T peek() { | |
} | ||
return null; | ||
} | ||
|
||
public LinkedList<T> extricate() { | ||
return inner; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,4 +57,7 @@ public boolean isFull() { | |
return false; | ||
} | ||
|
||
public LinkedList<T> extricate() { | ||
return inner; | ||
} | ||
} |
169 changes: 169 additions & 0 deletions
169
src/main/java/com/utp/clsEstructuraDatos/laboratorio_4/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<AppCollection<Integer>> collection; | ||
|
||
void new_collection() {} | ||
|
||
} | ||
|
||
sealed interface AppCollection<T> { | ||
// @formatter:off | ||
void insert(T element); | ||
Optional<T> pop(); | ||
Optional<T> peek(); | ||
boolean isEmpty(); | ||
boolean isFull(); | ||
void clear(); | ||
int len(); | ||
default AppCollection<T> extend_from(AppCollection<T> source){ | ||
switch (source) { | ||
case Stack<T>(var stack) -> { | ||
var element = stack.extricate | ||
this.insert() | ||
} | ||
case Queue<T>(var queue) -> { | ||
for (int i = 0; i < list.len(); i++) { | ||
queue.insert(list.get(i).get()); | ||
} | ||
return new Queue<>(queue); | ||
} | ||
case CircularQueue<T>(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<T>(LEPila<T> pila) implements AppCollection<T> { | ||
|
||
@Override | ||
public void insert(T element) { | ||
pila.push(element); | ||
} | ||
|
||
@Override | ||
public Optional<T> pop() { | ||
return Optional.ofNullable(pila.pop()); | ||
} | ||
|
||
@Override | ||
public Optional<T> 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<T>(LEColaLineal<T> lineal_queue) implements AppCollection<T> { | ||
|
||
@Override | ||
public void insert(T element) { | ||
lineal_queue.insert(element); | ||
} | ||
|
||
@Override | ||
public Optional<T> pop() { | ||
return Optional.ofNullable(lineal_queue.remove()); | ||
} | ||
|
||
@Override | ||
public Optional<T> 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<T>(LEColaCircular<T> looped_queue) implements AppCollection<T> { | ||
|
||
@Override | ||
public void insert(T element) { | ||
looped_queue.insert(element); | ||
} | ||
|
||
@Override | ||
public Optional<T> pop() { | ||
return Optional.ofNullable(looped_queue.remove()); | ||
} | ||
|
||
@Override | ||
public Optional<T> 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(); | ||
} | ||
} | ||
} |