Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,21 @@
import java.util.Stack;
public class StackTest {
public static void main( final String[] args ) {
final Stack<String> stack = new Stack<String>();
System.out.println( "New stack empty? " + stack.empty() );
stack.push( "There can be only one" );
System.out.println( "Pushed stack empty? " + stack.empty() );
System.out.println( "Popped single entry: " + stack.pop() );
stack.push( "First" );
stack.push( "Second" );
System.out.println( "Popped entry should be second: " + stack.pop() );
// Popping an empty stack will throw...
stack.pop();
stack.pop();
}
}

View 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;
}
}
}

View file

@ -0,0 +1,29 @@
public class Stack<T>{
private Node first = null;
public boolean isEmpty(){
return first == null;
}
public T Pop(){
if(isEmpty())
throw new Exception("Can't Pop from an empty Stack.");
else{
T temp = first.value;
first = first.next;
return temp;
}
}
public void Push(T o){
first = new Node(o, first);
}
class Node{
public Node next;
public T value;
public Node(T value){
this(value, null);
}
public Node(T value, Node next){
this.next = next;
this.value = value;
}
}
}