📄 stackvector.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc on Fri Aug 23 13:18:20 EDT 2002 --><TITLE>: Class StackVector</TITLE><LINK REL ="stylesheet" TYPE="text/css" HREF="../stylesheet.css" TITLE="Style"></HEAD><BODY BGCOLOR="white"><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><a href=../copyright.html target=_top>© 1998-2002 McGraw-Hill</a></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../structure/StackList.html"><B>PREV CLASS</B></A> <A HREF="../structure/StructCollection.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="StackVector.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | <A HREF="#field_summary">FIELD</A> | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: <A HREF="#field_detail">FIELD</A> | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">structure</FONT><BR>Class StackVector</H2><PRE><A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">java.lang.Object</A> | +--<A HREF="../structure/AbstractStructure.html">structure.AbstractStructure</A> | +--<A HREF="../structure/AbstractLinear.html">structure.AbstractLinear</A> | +--<A HREF="../structure/AbstractStack.html">structure.AbstractStack</A> | +--<B>structure.StackVector</B></PRE><DL><DT><B>All Implemented Interfaces:</B> <DD><A HREF="../structure/Linear.html">Linear</A>, <A HREF="../structure/Stack.html">Stack</A>, <A HREF="../structure/Structure.html">Structure</A></DD></DL><HR><DL><DT>public class <B>StackVector</B><DT>extends <A HREF="../structure/AbstractStack.html">AbstractStack</A><DT>implements <A HREF="../structure/Stack.html">Stack</A></DL><P>An implementation of a stack, based on extensible arrays. The head of the stack is stored in the first position of the list, allowing the stack to grow and shrink in constant time. This stack implementation is ideal for applications that require a dynamically resizable stack which occasionally takes a time proportional to the its length to expand. <P> Example usage: <P> To reverse a string with a stack array, we would use the following: <pre> public static void main(String[] arguments) { if(arguments.length > 0){ <A HREF="../structure/StackVector.html"><CODE>StackVector</CODE></A> reverseStack = new <A HREF="../structure/StackVector.html#StackVector()"><CODE>StackVector()</CODE></A>; String s = arguments[0]; for(int i=0; i < s.length(); i++){ reverseStack.<A HREF="../structure/AbstractStack.html#push(java.lang.Object)"><CODE>push(new Character(s.charAt(i)))</CODE></A>; } while(!reverseStack.<A HREF="../structure/AbstractLinear.html#empty()"><CODE>AbstractLinear.empty()</CODE></A>){ System.out.print(reverseStack.<A HREF="../structure/AbstractStack.html#pop()"><CODE>AbstractStack.pop()</CODE></A>); } System.out.println(); } } </pre><P><DL><DT><B>See Also: </B><DD><A HREF="../structure/Stack.html"><CODE>Stack</CODE></A>, <A HREF="../structure/StackList.html"><CODE>StackList</CODE></A>, <A HREF="../structure/StackArray.html"><CODE>StackArray</CODE></A>, <A HREF="../structure/AbstractStack.html"><CODE>AbstractStack</CODE></A></DL><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><A NAME="field_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Field Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected <A HREF="../structure/Vector.html">Vector</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/StackVector.html#data">data</A></B></CODE><BR> The vector containing the stack data.</TD></TR></TABLE> <!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Constructor Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../structure/StackVector.html#StackVector()">StackVector</A></B>()</CODE><BR> Construct an empty stack.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../structure/StackVector.html#StackVector(int)">StackVector</A></B>(int size)</CODE><BR> Construct a stack with initial capacity Vector will grow if the stack fills vector.</TD></TR></TABLE> <!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Method Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../structure/StackVector.html#add(java.lang.Object)">add</A></B>(<A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A> item)</CODE><BR> Add an element from the top of the stack.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../structure/StackVector.html#clear()">clear</A></B>()</CODE><BR> Remove all elements from stack.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/StackVector.html#get()">get</A></B>()</CODE><BR> Fetch a reference to the top element of the stack.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../structure/StackVector.html#isEmpty()">isEmpty</A></B>()</CODE><BR> Returns true iff the stack is empty.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/util/Iterator.html">Iterator</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/StackVector.html#iterator()">iterator</A></B>()</CODE><BR> Returns an iterator for traversing the structure.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/StackVector.html#remove()">remove</A></B>()</CODE><BR> Remove an element from the top of the stack.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int</CODE></FONT></TD><TD><CODE><B><A HREF="../structure/StackVector.html#size()">size</A></B>()</CODE><BR> Determine the number of elements in stack.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html">String</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/StackVector.html#toString()">toString</A></B>()</CODE><BR> Construct a string representation of stack.</TD></TR></TABLE> <A NAME="methods_inherited_from_class_structure.AbstractStack"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Methods inherited from class structure.<A HREF="../structure/AbstractStack.html">AbstractStack</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../structure/AbstractStack.html#getFirst()">getFirst</A>, <A HREF="../structure/AbstractStack.html#peek()">peek</A>, <A HREF="../structure/AbstractStack.html#pop()">pop</A>, <A HREF="../structure/AbstractStack.html#push(java.lang.Object)">push</A></CODE></TD></TR></TABLE> <A NAME="methods_inherited_from_class_structure.AbstractLinear"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Methods inherited from class structure.<A HREF="../structure/AbstractLinear.html">AbstractLinear</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../structure/AbstractLinear.html#empty()">empty</A>, <A HREF="../structure/AbstractLinear.html#remove(java.lang.Object)">remove</A></CODE></TD></TR></TABLE> <A NAME="methods_inherited_from_class_structure.AbstractStructure"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Methods inherited from class structure.<A HREF="../structure/AbstractStructure.html">AbstractStructure</A></B></TD></TR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -