以下代碼的大表示法是什麼?我仍然無法完全理解這個概念。 我應該從經驗豐富的編碼人員那裏得到一個基於此代碼的大o性能摘要。Java堆棧數組 - 大O表示法
import java.util.*;
import java.util.InputMismatchException;
import javax.swing.*;
public class MyStack {
private int maxSize;
private long[] stackArray;
private int top;
public MyStack(int s) {
maxSize = s;
stackArray = new long[maxSize];
top = -1;
}
public void push(long j) {
stackArray[++top] = j;
System.out.println("Push onto stack");
}
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) {
Scanner num = new Scanner(System.in);
int input =0;
int x;
MyStack theStack = new MyStack(5);
for(x=0; x<5; x++)
{
System.out.println("\nEnter a number(Push): ");
input = num.nextInt();
theStack.push(input);
}
System.out.print("The first element on the top is the top of the stack");
System.out.println("");
while (!theStack.isEmpty()) {
long value = theStack.pop();
System.out.print(value);
System.out.println(" Pop");
}
System.out.println("");
}
}
一個班級沒有大O的複雜性。你的問題是什麼? – 2015-06-15 07:00:45