/** * @param args */ @SuppressWarnings ({ "rawtypes", "Unchecked" &NBSP;}) public static void main (String[] args) { Stack Stack = new stack (); // Creating a Stack object System.out.println ("11111, absdder, 29999.3 three elements into the stack"); stack.push (New integer (11111)) //into stack pressing integers 11111 printstack (stack); //display all elements in the stack stack.push ("Absdder"); // Stack Press Printstack (stack); //displays all elements in the stack stack.push (new Double (29999.3)); //to stackMedium Press into printstack (stack), //display all elements in the stack string s = new string ("Absdder"); system.out.println ("element Absdder in the stack's position" +stack.search (s)); system.out.println ("element 11111 in the stack's position" +stack.search ( 11111)); system.out.println ("11111, absdder, 29999.3 Three elements out of the stack "); //popup Stack top element system.out.println (" Element "+stack.pop () +" out stack "); printstack (stack); // Displays all elements in the stack system.out.println ("element" +stack.pop () + "Out stack"); printstack (stack); //display all elements in the stack system.out.println ("element" +stack.pop () + "out stack"); printstack (stack); / /display all elements in the stack } @SuppressWarnings ("Rawtypes") private Static void printstack (stack<integer> stack ) { if (Stack.empty ()) System.out.println ("Stack is empty, no element"); else { System.out.print ("Elements in the Stack:"); enumeration items = stack.elements (); // Gets the enumeration object in stack while (Items.hasmoreelements ()) &NBSP;//Display Enumeration (stack ) all elements in system.out.print (items.nextelement () + " "); } System.out.println (); //line }
This article is from the "Listen to the Rain Hope Eternal" blog, please be sure to keep this source http://yongguang.blog.51cto.com/9153118/1709639
Java Stack access stack