c#自定义栈
标签:先进后出 log sharp stack mys blog == yield tac
栈的原理是先进后出。队列是先进先出。栈像乘坐电梯,后进的先出去。队列就是排队。
实现代码:
public class myStack
{
private int top;
private T[] stkArr;
private int maxSize;
///
/// 表示栈顶索引
///
public int Top
{
set { top = value; }
get { return top; }
}
public T[] StkArr
{
set { stkArr = value; }
get { return stkArr; }
}
public int MaxSize
{
get { return maxSize; }
set
{
if (value
/// 出栈
///
public T pop()
{
if (isNull())
{
throw new Exception("栈为空!");
}
else
{
return StkArr[--Top];
}
}
///
/// 入栈
///
public void pash(T value)
{
if (isFull())
{
throw new Exception("栈已满!");
}
else
{
StkArr[top++] = value;
}
}
///
/// 判断栈是否已满
///
///
public bool isFull()
{
return (Top == MaxSize);
}
///
/// 判断栈是否为空
///
///
public bool isNull()
{
return (Top == 0);
}
///
/// 返回栈大小
///
///
public int getMaxSize()
{
return MaxSize;
}
///
/// 遍历栈
///
///
public IEnumerable getEnumerable()
{
for (int i = 0; i
c#自定义栈
标签:先进后出 log sharp stack mys blog == yield tac
原文地址:http://www.cnblogs.com/sjyzz/p/7625340.html
文章来自:
搜素材网的
编程语言模块,转载请注明文章出处。
文章标题:
c#自定义栈
文章链接:http://soscw.com/index.php/essay/84093.html
评论