I am studying data structures and I have hit a bit of a road block. The top is Big oh notation and it is simply confusing. While I can find the upper bound for the simplest of loops, when it comes to the more complicated stuff, I get a bit lost.
I have got this Java stack array program that I am using as practice and was hoping if some here can show me how to find its upper bound.
Code:
import jeliot.io.*;
public class IStack {
private int maxSize;
private long[] stackArray;
private int top;
public IStack(int s) {
maxSize = s;
stackArray = new long[maxSize];
top = -1;
}
public void push(long j) {
stackArray[++top] = j;
}
public long pop() {
return stackArray[top--];
}
public long peek() {
return stackArray[top];
}
public boolean isEmpty() {
return (top == -1);
}
public boolean isFull() {
return (top == maxSize - 1);
}
public static void main(String[] args) {
IStack NStack = new IStack(5);
NStack.push(0);
NStack.push(1);
NStack.push(2);
NStack.push(3);
NStack.push(4);
while (!NStack.isEmpty()) {
long value = NStack.pop();
System.out.print("value: " + value);
System.out.print(" ");
}
System.out.println("");
}
}