class Stack<T>
{
private int count = 0;
private T [] arr;
public int size ()
{
return arr.length;
}
public void push(T item)
{
for (int i =0; i<arr.length;i++)
arr[i] = item;
// 這放東西進去
}
public T pop()
{
//這取第一個放的東西
}
public T peek()
{
//這顯示放進去的東西
}
我就是不知道怎樣寫求教想了很久了
public static void main(String args[]) {
Stack<Integer> stk = new Stack<Integer>();
stk.push(9);
System.out.println("Top item in stack: " + stk.peek());
stk.push(5);
System.out.println("Top item in stack: " + stk.peek());
stk.pop();
System.out.println("Top item in stack: " + stk.peek());
stk.push(7);
System.out.println("Top item in stack: " + stk.peek());
stk.push(3);
System.out.println("Top item in stack: " + stk.peek());
}
}
{
private int count = 0;
private T [] arr;
public int size ()
{
return arr.length;
}
public void push(T item)
{
for (int i =0; i<arr.length;i++)
arr[i] = item;
// 這放東西進去
}
public T pop()
{
//這取第一個放的東西
}
public T peek()
{
//這顯示放進去的東西
}
我就是不知道怎樣寫求教想了很久了
public static void main(String args[]) {
Stack<Integer> stk = new Stack<Integer>();
stk.push(9);
System.out.println("Top item in stack: " + stk.peek());
stk.push(5);
System.out.println("Top item in stack: " + stk.peek());
stk.pop();
System.out.println("Top item in stack: " + stk.peek());
stk.push(7);
System.out.println("Top item in stack: " + stk.peek());
stk.push(3);
System.out.println("Top item in stack: " + stk.peek());
}
}
