<html>

<head><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- MyFirstUnitAd -->
<ins class="adsbygoogle"
     style="display:inline-block;width:970px;height:250px"
     data-ad-client="ca-pub-5778386704669218"
     data-ad-slot="1503492166"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Puzzle</title>
</head>

<body>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#FF0000" size="6"><b>&nbsp;</b></font><font color="#FF0000" size="6"><b>&nbsp;&nbsp;&nbsp;  
我的</b></font><font color="#FF0000" size="6"><b>Stack</b></font>  
</p>
<div align="left">
  <pre><b><font color="#ff0000" size="5">A.第一版</font></b></pre>
</div>
<div align="left">
  <pre><b>这个小程序是第一版。（会有第二版吗？）</b></pre>
</div>
<div align="left">
  <pre><b>1。 程序基本说明：用数组结合模板实现的极其简单的数据结构---stack。</b></pre>
</div>
<div align="left">
  <pre><b>2。 程序思路：栈底在数组的0位置，数组的上限就是栈的上限，用一个index来标定当前的栈顶，很土吧？	</b></pre>
</div>
<div align="left">
  <pre><b>3。 主要函数介绍：</b></pre>
</div>
<div style="WIDTH: 892px; HEIGHT: 102px" align="left">
  <pre><b>     A.  T pop();
	   void push(T element);</b></pre>
  <pre><b>	stack的基本操作，简单判断empty和溢出的情况。没什么好说的。</b></pre>
  <pre><b>4。 不足之处：</b></pre>
  <pre><b>	A. 随便写的，计划再用链表实现一遍。</b></pre>
</div>
<div align="left">
  <pre><b>		</b></pre>
</div>
<pre>#include &lt;iostream&gt;</pre>
<pre>using namespace std;</pre>
<pre>const int MaxLen = 100;
</pre>
<pre>template &lt;class T&gt;
class Stack
{
private:
	T lst[MaxLen];
	int domino;
public:
	T pop();
	void push(T element);
	Stack();
	bool empty();
	bool full();
};</pre>
<pre>int main()
{
	Stack&lt;int&gt; intStack;
	for (int i=0; i&lt;10; i++)
	{
		intStack.push(i*2);
	}</pre>
<pre>	for (i =0; i&lt; 12; i++)
	{
		cout&lt;&lt;i&lt;&lt;&quot; is &quot;&lt;&lt;intStack.pop()&lt;&lt;&quot;\n&quot;;
	}
	return 0;
}</pre>
<pre>template&lt;class T&gt;
bool Stack&lt;T&gt;::full()
{
	return (domino==MaxLen);
}</pre>
<pre>template&lt;class T&gt;
Stack&lt;T&gt;::Stack()
{
	domino =0;
}</pre>
<pre>template&lt;class T&gt;
bool Stack&lt;T&gt;::empty()
{
	return (domino==0);
}</pre>
<pre>template&lt;class T&gt;
T Stack&lt;T&gt;::pop()
{
	if (!empty())
	{
		domino--;
		return lst[domino];	
	}
	else
	{
		cout&lt;&lt;&quot;\nEmpty!\n&quot;;
		return NULL;
	}
}</pre>
<pre>template&lt;class T&gt;
void Stack&lt;T&gt;::push(T element)
{
	if (!full())
	{
		lst[domino]= element;
		domino++;
	}
	else
	{
		cout&lt;&lt;&quot;\noverflow!\n&quot;;
	}
}</pre>
<pre><img border="0" src="picture/stack.JPG" width="672" height="430"></pre>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;          
&nbsp;&nbsp;&nbsp; <a href="Matrix1.htm">      







                       <img src="picture/back.gif" style="border: medium none" alt="back.gif (341 bytes)" width="32" height="35"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
<a href="index.htm"><img src="picture/up.gif" style="border: medium none" alt="up.gif (335 bytes)" width="35" height="32"></a>       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<a href="possibility.htm"><img src="picture/next.gif" style="border: medium none" alt="next.gif (337 bytes)" width="32" height="35">          


</a>          


</p>

</body>

</html>
