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.
Estructura de Datos - Lab 4 : Lista Enlazada
* Lista enlazada * Expan Queues impls * Pila con Linked List * Refactor LEPila's hierarchy * Add a Peek method to queues * Stage Changes * Stage changes * App implementation * Presentable de laboratorio
- Loading branch information
Showing
10 changed files
with
863 additions
and
3 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/com/utp/clsEstructuraDatos/Estructuras/colas/AbstractLinkedQueue.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,39 @@ | ||
package com.utp.clsEstructuraDatos.Estructuras.colas; | ||
|
||
import com.utp.clsEstructuraDatos.Estructuras.linked_list.LinkedList; | ||
|
||
public abstract class AbstractLinkedQueue<T> implements IQueue<T> { | ||
protected LinkedList<T> inner = new LinkedList<>(); | ||
protected int len = 0; | ||
|
||
@Override | ||
/** | ||
* Linked List has no capacity constraint | ||
*/ | ||
public boolean isFull() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int len() { | ||
return this.len; | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
inner.clear(); | ||
this.len = 0; | ||
} | ||
|
||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("["); | ||
for (int i = 0; i < inner.len(); i++) { | ||
sb.append(inner.get(i).get().toString()); | ||
sb.append(", "); | ||
} | ||
sb.delete(sb.length() - 2, sb.length()); | ||
sb.append("]"); | ||
return sb.toString(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/utp/clsEstructuraDatos/Estructuras/colas/IQueue.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,19 @@ | ||
package com.utp.clsEstructuraDatos.Estructuras.colas; | ||
|
||
public interface IQueue<T> { | ||
default boolean isEmpty() { | ||
return (len() == 0); | ||
} | ||
|
||
boolean isFull(); | ||
|
||
void insert(T elemento); | ||
|
||
T remove(); | ||
|
||
T peek(); | ||
|
||
int len(); | ||
|
||
void clear(); | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/utp/clsEstructuraDatos/Estructuras/linked_list/LEColaCircular.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,35 @@ | ||
package com.utp.clsEstructuraDatos.Estructuras.linked_list; | ||
|
||
import com.utp.clsEstructuraDatos.Estructuras.colas.AbstractLinkedQueue; | ||
|
||
public class LEColaCircular<T> extends AbstractLinkedQueue<T> { | ||
|
||
@Override | ||
public void insert(T elemento) { | ||
len += 1; | ||
inner.insert_last(elemento); | ||
} | ||
|
||
@Override | ||
public T remove() { | ||
if (this.isEmpty()) { | ||
return null; | ||
} | ||
len -= 1; | ||
return inner.remove_first().get(); | ||
} | ||
|
||
@Override | ||
public T peek() { | ||
var e = inner.get(0); | ||
if (e.isPresent()) { | ||
return e.get(); | ||
} | ||
return null; | ||
} | ||
|
||
public LinkedList<T> extricate() { | ||
return inner; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/utp/clsEstructuraDatos/Estructuras/linked_list/LEColaLineal.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,43 @@ | ||
package com.utp.clsEstructuraDatos.Estructuras.linked_list; | ||
|
||
import com.utp.clsEstructuraDatos.Estructuras.colas.AbstractLinkedQueue; | ||
|
||
public class LEColaLineal<T> extends AbstractLinkedQueue<T> { | ||
|
||
/** | ||
* Append at the end of the queue | ||
*/ | ||
@Override | ||
public void insert(T elemento) { | ||
len += 1; | ||
inner.insert_last(elemento); | ||
} | ||
|
||
/** | ||
* Remove the latest inserted element from the queue | ||
*/ | ||
@Override | ||
public T remove() { | ||
if (this.isEmpty()) { | ||
return null; | ||
} | ||
if (inner.len() == 1) { | ||
len = 0; | ||
} | ||
return inner.remove_first().get(); | ||
} | ||
|
||
@Override | ||
public T peek() { | ||
var e = inner.get(0); | ||
if (e.isPresent()) { | ||
return e.get(); | ||
} | ||
return null; | ||
} | ||
|
||
public LinkedList<T> extricate() { | ||
return inner; | ||
} | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/utp/clsEstructuraDatos/Estructuras/linked_list/LEPila.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,80 @@ | ||
package com.utp.clsEstructuraDatos.Estructuras.linked_list; | ||
|
||
import com.utp.clsEstructuraDatos.Estructuras.pila.IStack; | ||
|
||
public class LEPila<T> implements IStack<T> { | ||
int len = 0; | ||
LinkedList<T> inner = new LinkedList<T>(); | ||
|
||
@Override | ||
public void push(T elemento) { | ||
len += 1; | ||
inner.insert_first(elemento); | ||
} | ||
|
||
@Override | ||
public T pop() { | ||
if (isEmpty()) { | ||
return null; | ||
} | ||
var e = inner.remove_first(); | ||
len -= 1; | ||
if (e.isPresent()) { | ||
return e.get(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public T peek_top() { | ||
var e = inner.get(0); | ||
if (e.isPresent()) { | ||
return e.get(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public int len() { | ||
return this.len; | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
len = 0; | ||
inner.clear(); | ||
} | ||
|
||
@Override | ||
public int capacity() { | ||
return -1; | ||
} | ||
|
||
@Override | ||
/** | ||
* Linked List has no capacity constraint | ||
*/ | ||
public boolean isFull() { | ||
return false; | ||
} | ||
|
||
public LinkedList<T> to_inverted() { | ||
var inner = new LinkedList<T>(); | ||
for (int i = len - 1; i >= 0; i--) { | ||
inner.insert_first(this.inner.get(i).get()); | ||
} | ||
return inner; | ||
} | ||
|
||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("["); | ||
for (int i = 0; i < len; i++) { | ||
sb.append(inner.get(i).get().toString()); | ||
sb.append("| "); | ||
} | ||
sb.delete(sb.length() - 2, sb.length()); | ||
sb.append("]"); | ||
return sb.toString(); | ||
} | ||
} |
Oops, something went wrong.