Created
November 23, 2017 04:39
-
-
Save shah-smit/8ece27d24c84c8fa3971912e167d4aa9 to your computer and use it in GitHub Desktop.
ArrayList implemented through Array
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
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