Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class stackofints<Item>
- {
- private static node topofstack=null;
- private static class node{
- Item item;
- node next;
- }
- public static void push(Item item){
- node oldtopofstack=topofstack;
- topofstack=new node();
- topofstack.item=item;
- topofstack.next=oldtopofstack;
- }
- public static int pop(){
- Item item=topofstack.item;
- topofstack=topofstack.next;
- return item;
- }
- public boolean isEmpty(){return topofstack==null;}
- public static Item size(){
- Item i=0;
- node iterate=topofstack;
- while(iterate!=null)
- {
- iterate=iterate.next;
- i++;
- }
- return i;
- }
- public static void main(String[] args)
- {
- push(1);
- push(2);
- push(3);
- System.out.println(size());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement