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
5 changed files
with
102 additions
and
3 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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/utp/clsEstructuraDatos/Estructuras/pila/IStack.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,23 @@ | ||
package com.utp.clsEstructuraDatos.Estructuras.pila; | ||
|
||
public interface IStack<T> { | ||
default boolean isEmpty() { | ||
return (len() == 0); | ||
} | ||
|
||
default boolean isFull() { | ||
return len() == capacity(); | ||
} | ||
|
||
void push(T elemento); | ||
|
||
T pop(); | ||
|
||
T peek_top(); | ||
|
||
int len(); | ||
|
||
void clear(); | ||
|
||
int capacity(); | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/utp/clsEstructuraDatos/Estructuras/pila/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,60 @@ | ||
package com.utp.clsEstructuraDatos.Estructuras.pila; | ||
|
||
import com.utp.clsEstructuraDatos.Estructuras.linked_list.LinkedList; | ||
|
||
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() { | ||
inner.clear(); | ||
} | ||
|
||
@Override | ||
public int capacity() { | ||
return -1; | ||
} | ||
|
||
@Override | ||
/** | ||
* Linked List has no capacity constraint | ||
*/ | ||
public boolean isFull() { | ||
return false; | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
.../clsEstructuraDatos/Estructuras/Pila.java → ...structuraDatos/Estructuras/pila/Pila.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
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