About stack

xiaoxiao2021-03-06  41

Use the program to explain everything package com.tianyu.summer;

/ ** * @Author Summer * * / import java.util. *;

Public class stacktest {

Public stacktest () {strack stack = new stack ();

Boolean Bool = Boolean.true; Character Character = New Character ('$'); / ** * The stack stack must be pressed into the Object type, so all the types of the previously defined is the subclass of Object * / Try {Stack. Push (Bool); PrintStack; stack.push (character); PrintStack; / ** * When you need to bring a parameter when you want to pop up, you don't need to bring a parameter because the stack is a certain pop-up law, if you bring your own parameters The program will be wrong * / stack.pop (); // printstack; stack.pop (); printstack; stack.pop ();} catch (emptystackedException e) {/ ** * throw Java. Util.emptystackexception at java.util.stack.peek (unknown * Source) at java.util.stack.pop (unknown source) at * com.tianu.summer.stacktest. (stacktest.java: 31) AT * Com.tianiu.summer.stackTest.main (stacktest.java: 64) * Because the stack is empty, it is no longer possible to make a fill operation * / E.PrintStackTrace ();}}

Public void printstack (stack stack) {if (stack.Isempty ()) {system.out.println ("stack is empty");} else {system.out.print ("stack contains:"); enumeration items = stack .Elements (); while (items.hasmorelements ()) {system.out.print (items.nextelement () ");} system.out.print (" / n ");}}

Public void removestack (stack stack) {if (stack.Isempty ()) {system.out.println ("stack is empty");} else {system.out.print ("stack contains:"); enumeration items = stack .Elements (); while (items.hasmorelements ()) {system.out.print (items.nextelement () ");} system.out.print (" / n ");}}

Public static void main (string [] args) {new stacktest ();}}

转载请注明原文地址:https://www.9cbs.com/read-86168.html

New Post(0)