Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
29
Task/Stack/Java/stack-2.java
Normal file
29
Task/Stack/Java/stack-2.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
public class Stack{
|
||||
private Node first = null;
|
||||
public boolean isEmpty(){
|
||||
return first == null;
|
||||
}
|
||||
public Object Pop(){
|
||||
if(isEmpty())
|
||||
throw new Exception("Can't Pop from an empty Stack.");
|
||||
else{
|
||||
Object temp = first.value;
|
||||
first = first.next;
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
public void Push(Object o){
|
||||
first = new Node(o, first);
|
||||
}
|
||||
class Node{
|
||||
public Node next;
|
||||
public Object value;
|
||||
public Node(Object value){
|
||||
this(value, null);
|
||||
}
|
||||
public Node(Object value, Node next){
|
||||
this.next = next;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue