Skip to content

Instantly share code, notes, and snippets.

@shah-smit
Created November 23, 2017 04:39
Show Gist options
  • Save shah-smit/8ece27d24c84c8fa3971912e167d4aa9 to your computer and use it in GitHub Desktop.
Save shah-smit/8ece27d24c84c8fa3971912e167d4aa9 to your computer and use it in GitHub Desktop.
ArrayList implemented through Array
import java.io.*;
public class Stack
{
Node[] stack;
public Stack(){
stack = new Node[0];
}
public void pop(){
if(stack.length != 0){
Node[] newStack = new Node[stack.length-1];
for(int i=1; i<newStack.length; i++){
newStack[i-1] = stack[i];
}
}
}
public void push(Node n){
Node[] newStack = new Node[stack.length+1];
newStack[0] = n;
for(int i=1; i<newStack.length; i++){
newStack[i] = stack[i-1];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment