Stack using Collection Stack Class in DSA Java

Program 1

package dataflair;
import java.util.*;
public class StackCollection 
{
    public static void main(String[] args) 
    {
        Stack<Integer>mystack=new Stack<Integer>();
        //  System.out.println("Before Push size: "+mystack.size());
//          System.out.println("Before Push Empty : "+mystack.isEmpty());
        mystack.push(100);
        mystack.push(500);
        mystack.push(200);
        mystack.push(700);
        mystack.push(400);
        mystack.push(300);
        System.out.println(mystack);
        
       //System.out.println(mystack);
//        for(Integer I :mystack)
//        {
//            System.out.println(I);
//        }
        
//        ListIterator I1=mystack.listIterator();
//        while(I1.hasNext())
//        {
//            System.out.println(I1.next());
//        }
        
//        System.out.println("-----------Before Sorting-------------");
//        int n;
//        n=mystack.size();
//        ListIterator I=mystack.listIterator(n);
//        while(I.hasPrevious())
//        {
//            System.out.println(I.previous());
//        }
        
//        System.out.println("-----------After Sorting-------------");
//        
//        n=mystack.size();
//        ListIterator I1=mystack.listIterator(n);
//        while(I1.hasPrevious())
//        {
//            System.out.println(I.previous());
//        }
        
        
    //    System.out.println(mystack.search(1200));
        
//        System.out.println("After Push size: "+mystack.size());
////        System.out.println("After Push Empty contidition: "+mystack.isEmpty());
//        System.out.println("Poped Element: "+mystack.pop());
//        System.out.println("After Poped size: "+mystack.size());
//        
    }
    
}

 

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *