java数据结构之栈
来源:互联网 发布:淘宝店装修软件 编辑:程序博客网 时间:2024/04/30 05:03
- 栈接口
- <div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"><div><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> pku.ss.datastructure.IStackLi; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"> <br><img id="_71_1080_Open_Image" onclick="this.style.display='none'; document.getElementById('_71_1080_Open_Text').style.display='none'; document.getElementById('_71_1080_Closed_Image').style.display='inline'; document.getElementById('_71_1080_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif"><img id="_71_1080_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_71_1080_Closed_Text').style.display='none'; document.getElementById('_71_1080_Open_Image').style.display='inline'; document.getElementById('_71_1080_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">interface</span><span style="COLOR: #000000"> IStackLi </span><span id="_71_1080_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_71_1080_Open_Text"><span style="COLOR: #000000">{ <br><img id="_80_162_Open_Image" onclick="this.style.display='none'; document.getElementById('_80_162_Open_Text').style.display='none'; document.getElementById('_80_162_Closed_Image').style.display='inline'; document.getElementById('_80_162_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_80_162_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_80_162_Closed_Text').style.display='none'; document.getElementById('_80_162_Open_Image').style.display='inline'; document.getElementById('_80_162_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span id="_80_162_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/** */</span><span id="_80_162_Open_Text"><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> * Get the size of the stack <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> * </span><span style="COLOR: #808080">@return</span><span style="COLOR: #008000"> size of the stack <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> getSize(); <br><img id="_199_283_Open_Image" onclick="this.style.display='none'; document.getElementById('_199_283_Open_Text').style.display='none'; document.getElementById('_199_283_Closed_Image').style.display='inline'; document.getElementById('_199_283_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_199_283_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_199_283_Closed_Text').style.display='none'; document.getElementById('_199_283_Open_Image').style.display='inline'; document.getElementById('_199_283_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span id="_199_283_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/** */</span><span id="_199_283_Open_Text"><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> * Judge that if the stack is full <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> * </span><span style="COLOR: #808080">@return</span><span style="COLOR: #008000"> true or false <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> isFull(); <br><img id="_323_408_Open_Image" onclick="this.style.display='none'; document.getElementById('_323_408_Open_Text').style.display='none'; document.getElementById('_323_408_Closed_Image').style.display='inline'; document.getElementById('_323_408_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_323_408_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_323_408_Closed_Text').style.display='none'; document.getElementById('_323_408_Open_Image').style.display='inline'; document.getElementById('_323_408_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span id="_323_408_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/** */</span><span id="_323_408_Open_Text"><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> * Judge that if the stack is empty <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> * </span><span style="COLOR: #808080">@return</span><span style="COLOR: #008000"> true or false <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> isEmpty(); <br><img id="_449_496_Open_Image" onclick="this.style.display='none'; document.getElementById('_449_496_Open_Text').style.display='none'; document.getElementById('_449_496_Closed_Image').style.display='inline'; document.getElementById('_449_496_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_449_496_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_449_496_Closed_Text').style.display='none'; document.getElementById('_449_496_Open_Image').style.display='inline'; document.getElementById('_449_496_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span id="_449_496_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/** */</span><span id="_449_496_Open_Text"><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> * Set the stack to be empty <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> makeEmpty(); <br><img id="_536_706_Open_Image" onclick="this.style.display='none'; document.getElementById('_536_706_Open_Text').style.display='none'; document.getElementById('_536_706_Closed_Image').style.display='inline'; document.getElementById('_536_706_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_536_706_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_536_706_Closed_Text').style.display='none'; document.getElementById('_536_706_Open_Image').style.display='inline'; document.getElementById('_536_706_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span id="_536_706_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/** */</span><span id="_536_706_Open_Text"><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> * Push a element x into stack, if the operation is right then return true, <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> * else return false <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> x <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> * </span><span style="COLOR: #808080">@return</span><span style="COLOR: #008000"> true or false <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> push(Object x); <br><img id="_752_842_Open_Image" onclick="this.style.display='none'; document.getElementById('_752_842_Open_Text').style.display='none'; document.getElementById('_752_842_Closed_Image').style.display='inline'; document.getElementById('_752_842_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_752_842_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_752_842_Closed_Text').style.display='none'; document.getElementById('_752_842_Open_Image').style.display='inline'; document.getElementById('_752_842_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span id="_752_842_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/** */</span><span id="_752_842_Open_Text"><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> * return the top element of the stack <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> * </span><span style="COLOR: #808080">@return</span><span style="COLOR: #008000"> the top element <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> Object top(); <br><img id="_878_1039_Open_Image" onclick="this.style.display='none'; document.getElementById('_878_1039_Open_Text').style.display='none'; document.getElementById('_878_1039_Closed_Image').style.display='inline'; document.getElementById('_878_1039_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_878_1039_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_878_1039_Closed_Text').style.display='none'; document.getElementById('_878_1039_Open_Image').style.display='inline'; document.getElementById('_878_1039_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span id="_878_1039_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/** */</span><span id="_878_1039_Open_Text"><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> * Pop the top element from the stack, if the operation is right, then return <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> * true, else return false <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> * </span><span style="COLOR: #808080">@return</span><span style="COLOR: #008000"> true or false <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> pop(); <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"></span></div></div>
2,栈的实现- <div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"><div><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> pku.ss.datastructure.StackLi; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> pku.ss.datastructure.IStackLi.IStackLi; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"> <br><img id="_138_1751_Open_Image" onclick="this.style.display='none'; document.getElementById('_138_1751_Open_Text').style.display='none'; document.getElementById('_138_1751_Closed_Image').style.display='inline'; document.getElementById('_138_1751_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif"><img id="_138_1751_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_138_1751_Closed_Text').style.display='none'; document.getElementById('_138_1751_Open_Image').style.display='inline'; document.getElementById('_138_1751_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> StackLi </span><span style="COLOR: #0000ff">implements</span><span style="COLOR: #000000"> IStackLi </span><span id="_138_1751_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_138_1751_Open_Text"><span style="COLOR: #000000">{ <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> maxSize; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> size; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> ListNode topOfStack; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> <br><img id="_267_362_Open_Image" onclick="this.style.display='none'; document.getElementById('_267_362_Open_Text').style.display='none'; document.getElementById('_267_362_Closed_Image').style.display='inline'; document.getElementById('_267_362_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_267_362_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_267_362_Closed_Text').style.display='none'; document.getElementById('_267_362_Open_Image').style.display='inline'; document.getElementById('_267_362_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> StackLi(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> maxSize) </span><span id="_267_362_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_267_362_Open_Text"><span style="COLOR: #000000">{ <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.maxSize </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> maxSize; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> size </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> topOfStack </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> }</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> @Override <br><img id="_411_449_Open_Image" onclick="this.style.display='none'; document.getElementById('_411_449_Open_Text').style.display='none'; document.getElementById('_411_449_Closed_Image').style.display='inline'; document.getElementById('_411_449_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_411_449_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_411_449_Closed_Text').style.display='none'; document.getElementById('_411_449_Open_Image').style.display='inline'; document.getElementById('_411_449_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> getSize() </span><span id="_411_449_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_411_449_Open_Text"><span style="COLOR: #000000">{ <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.size; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> }</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> @Override <br><img id="_502_540_Open_Image" onclick="this.style.display='none'; document.getElementById('_502_540_Open_Text').style.display='none'; document.getElementById('_502_540_Closed_Image').style.display='inline'; document.getElementById('_502_540_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_502_540_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_502_540_Closed_Text').style.display='none'; document.getElementById('_502_540_Open_Image').style.display='inline'; document.getElementById('_502_540_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> isEmpty() </span><span id="_502_540_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_502_540_Open_Text"><span style="COLOR: #000000">{ <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> size </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> }</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> @Override <br><img id="_592_639_Open_Image" onclick="this.style.display='none'; document.getElementById('_592_639_Open_Text').style.display='none'; document.getElementById('_592_639_Closed_Image').style.display='inline'; document.getElementById('_592_639_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_592_639_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_592_639_Closed_Text').style.display='none'; document.getElementById('_592_639_Open_Image').style.display='inline'; document.getElementById('_592_639_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> isFull() </span><span id="_592_639_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_592_639_Open_Text"><span style="COLOR: #000000">{ <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> size </span><span style="COLOR: #000000">></span><span style="COLOR: #000000"> maxSize </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> }</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> @Override <br><img id="_691_751_Open_Image" onclick="this.style.display='none'; document.getElementById('_691_751_Open_Text').style.display='none'; document.getElementById('_691_751_Closed_Image').style.display='inline'; document.getElementById('_691_751_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_691_751_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_691_751_Closed_Text').style.display='none'; document.getElementById('_691_751_Open_Image').style.display='inline'; document.getElementById('_691_751_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> makeEmpty() </span><span id="_691_751_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_691_751_Open_Text"><span style="COLOR: #000000">{ <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> size </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> topOfStack </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> }</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> @Override <br><img id="_800_1075_Open_Image" onclick="this.style.display='none'; document.getElementById('_800_1075_Open_Text').style.display='none'; document.getElementById('_800_1075_Closed_Image').style.display='inline'; document.getElementById('_800_1075_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_800_1075_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_800_1075_Closed_Text').style.display='none'; document.getElementById('_800_1075_Open_Image').style.display='inline'; document.getElementById('_800_1075_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> pop() </span><span id="_800_1075_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_800_1075_Open_Text"><span style="COLOR: #000000">{ <br><img id="_828_950_Open_Image" onclick="this.style.display='none'; document.getElementById('_828_950_Open_Text').style.display='none'; document.getElementById('_828_950_Closed_Image').style.display='inline'; document.getElementById('_828_950_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_828_950_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_828_950_Closed_Text').style.display='none'; document.getElementById('_828_950_Open_Image').style.display='inline'; document.getElementById('_828_950_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (isEmpty()) </span><span id="_828_950_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_828_950_Open_Text"><span style="COLOR: #000000">{ <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> System.out.println(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">[ERROR] Atempt to pop from a empty stack!</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">); <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">; <br><img id="_957_1066_Open_Image" onclick="this.style.display='none'; document.getElementById('_957_1066_Open_Text').style.display='none'; document.getElementById('_957_1066_Closed_Image').style.display='inline'; document.getElementById('_957_1066_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_957_1066_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_957_1066_Closed_Text').style.display='none'; document.getElementById('_957_1066_Open_Image').style.display='inline'; document.getElementById('_957_1066_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> }</span></span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> </span><span id="_957_1066_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_957_1066_Open_Text"><span style="COLOR: #000000">{ <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> topOfStack </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> topOfStack.next; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> size</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> }</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> }</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> @Override <br><img id="_1133_1483_Open_Image" onclick="this.style.display='none'; document.getElementById('_1133_1483_Open_Text').style.display='none'; document.getElementById('_1133_1483_Closed_Image').style.display='inline'; document.getElementById('_1133_1483_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_1133_1483_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_1133_1483_Closed_Text').style.display='none'; document.getElementById('_1133_1483_Open_Image').style.display='inline'; document.getElementById('_1133_1483_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> push(Object x) </span><span id="_1133_1483_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_1133_1483_Open_Text"><span style="COLOR: #000000">{ <br><img id="_1160_1282_Open_Image" onclick="this.style.display='none'; document.getElementById('_1160_1282_Open_Text').style.display='none'; document.getElementById('_1160_1282_Closed_Image').style.display='inline'; document.getElementById('_1160_1282_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_1160_1282_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_1160_1282_Closed_Text').style.display='none'; document.getElementById('_1160_1282_Open_Image').style.display='inline'; document.getElementById('_1160_1282_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (isFull()) </span><span id="_1160_1282_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_1160_1282_Open_Text"><span style="COLOR: #000000">{ <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> System.out.println(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">[ERROR] Atempt to push into a full stack!</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">); <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">; <br><img id="_1289_1474_Open_Image" onclick="this.style.display='none'; document.getElementById('_1289_1474_Open_Text').style.display='none'; document.getElementById('_1289_1474_Closed_Image').style.display='inline'; document.getElementById('_1289_1474_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_1289_1474_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_1289_1474_Closed_Text').style.display='none'; document.getElementById('_1289_1474_Open_Image').style.display='inline'; document.getElementById('_1289_1474_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> }</span></span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> </span><span id="_1289_1474_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_1289_1474_Open_Text"><span style="COLOR: #000000">{ <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> ListNode temp </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> ListNode(x); <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> temp.next </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> topOfStack; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> topOfStack </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> temp; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> size</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> }</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> }</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> @Override <br><img id="_1531_1743_Open_Image" onclick="this.style.display='none'; document.getElementById('_1531_1743_Open_Text').style.display='none'; document.getElementById('_1531_1743_Closed_Image').style.display='inline'; document.getElementById('_1531_1743_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_1531_1743_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_1531_1743_Closed_Text').style.display='none'; document.getElementById('_1531_1743_Open_Image').style.display='inline'; document.getElementById('_1531_1743_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> Object top() </span><span id="_1531_1743_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_1531_1743_Open_Text"><span style="COLOR: #000000">{ <br><img id="_1559_1696_Open_Image" onclick="this.style.display='none'; document.getElementById('_1559_1696_Open_Text').style.display='none'; document.getElementById('_1559_1696_Closed_Image').style.display='inline'; document.getElementById('_1559_1696_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_1559_1696_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_1559_1696_Closed_Text').style.display='none'; document.getElementById('_1559_1696_Open_Image').style.display='inline'; document.getElementById('_1559_1696_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (isEmpty()) </span><span id="_1559_1696_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_1559_1696_Open_Text"><span style="COLOR: #000000">{ <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> System.out.println(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">[ERROR] Atempt to get the top element from a empty stack!</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">); <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> }</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> topOfStack.element; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> }</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"></span></div></div>
3,节点类型- <div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"><div><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> pku.ss.datastructure.StackLi; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"> <br><img id="_66_350_Open_Image" onclick="this.style.display='none'; document.getElementById('_66_350_Open_Text').style.display='none'; document.getElementById('_66_350_Closed_Image').style.display='inline'; document.getElementById('_66_350_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif"><img id="_66_350_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_66_350_Closed_Text').style.display='none'; document.getElementById('_66_350_Open_Image').style.display='inline'; document.getElementById('_66_350_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> ListNode </span><span id="_66_350_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_66_350_Open_Text"><span style="COLOR: #000000">{ <br><img id="_103_147_Open_Image" onclick="this.style.display='none'; document.getElementById('_103_147_Open_Text').style.display='none'; document.getElementById('_103_147_Closed_Image').style.display='inline'; document.getElementById('_103_147_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_103_147_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_103_147_Closed_Text').style.display='none'; document.getElementById('_103_147_Open_Image').style.display='inline'; document.getElementById('_103_147_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> ListNode(Object theElement) </span><span id="_103_147_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_103_147_Open_Text"><span style="COLOR: #000000">{ <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">(theElement, </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">); <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> }</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> <br><img id="_203_270_Open_Image" onclick="this.style.display='none'; document.getElementById('_203_270_Open_Text').style.display='none'; document.getElementById('_203_270_Closed_Image').style.display='inline'; document.getElementById('_203_270_Closed_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"><img id="_203_270_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_203_270_Closed_Text').style.display='none'; document.getElementById('_203_270_Open_Image').style.display='inline'; document.getElementById('_203_270_Open_Text').style.display='inline';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"> ListNode(Object theElement, ListNode aNext) </span><span id="_203_270_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span><span id="_203_270_Open_Text"><span style="COLOR: #000000">{ <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> element </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> theElement; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> next </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> aNext; <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif"> }</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"> Object element; </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">节点中的元素 </span><span style="COLOR: #008000"><br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000"> ListNode next; </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">指向下一个节点 </span><span style="COLOR: #008000"><br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif"></span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000"> <br><img align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"></span></div></div>
4,测试类package pku.ss.datastructure.Demo;
import pku.ss.datastructure.StackLi.StackLi;
public class StackLiDemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
StackLi stack = new StackLi(5);
stack.push("A");
stack.push("B");
stack.push("C");
stack.push("D");
stack.push("E");
stack.push("F");
stack.push("G");
stack.push("H");
System.out.println("**********************");
System.out.println("The size of the stack is: " + stack.getSize());
System.out.println("**********************");
System.out.println("The top element of the stack is: " + stack.top());
System.out.println("**********************");
stack.makeEmpty();
System.out.println("The top element of the stack is: " + stack.top());
System.out.println("**********************");
System.out.println("The size of the stack is: " + stack.getSize());
}
}
0 0
- java数据结构之栈
- java数据结构之栈
- java数据结构之栈
- Java 数据结构之 Stack(栈)
- java 数据结构一 之栈
- JAVA 数据结构之栈实现
- Java数据结构之链式栈
- 数据结构之栈(java版)
- Java数据结构实现之栈
- 【数据结构】之链栈的java实现
- 数据结构之栈的java实现
- 数据结构java版之线性表,栈
- java 数据结构之 顺序存储结构 栈
- java 数据结构之 链式存储结构 栈
- 【数据结构】之链栈的java实现
- Java数据结构与算法之栈
- 数据结构之栈的Java实现
- 【数据结构】之链栈的java实现
- Java工具包:小写金额转换成大写金额
- 移动界面尺寸
- cocostudi界面和cocos2dx代码绑定
- 编译器级别的代码优化对比
- 一个多maven项目聚合的实例
- java数据结构之栈
- Android开发之动画源码Animation详细分析
- Spring的基本框架
- 指针常量与常量指针 C++
- csu 1460: Kastenlauf
- 中文文献BibTeX制作
- day74(clone用法)
- 25个增强iOS应用程序性能的提示和技巧(初级篇)
- C语言中内存分布及程序运行中(BSS段、数据段、代码段、堆栈)