Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication3;
- import java.util.ArrayList;
- import java.util.List;
- /**
- *
- * @author student
- */
- public class MyStack {
- private List<Object> list = new ArrayList<Object>();
- public boolean isEmpty(){
- return list.isEmpty();
- }
- public int getSize(){
- return list.size();
- }
- public Object peek(){
- return (Object)list.get(list.size()-1);
- }
- public Object pop(){
- Object a = list.get(list.size()-1);
- list.remove(a);
- return a;
- }
- public void push (Object o){
- list.add(o);
- }
- public int search (Object o){
- for(int i=0; i< this.getSize();i++)
- if(list.get(i).equals(o))
- return i;
- return -1;
- }
- @Override
- public String toString() {
- return "MyStack{" + "list=" + list + '}';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement