genericstack.cs
来自「这是.net2005学习不可缺少的教程」· CS 代码 · 共 37 行
CS
37 行
using System;
using System.Collections.Generic;
using System.Text;
namespace Generics
{
public class GenericStack<T>
{
// Backing store
private T[] frames;
// Stack pointer (points to the next free stack frame)
private int pointer = 0;
// Constructor (initialises the backing store)
public GenericStack(int size)
{
this.frames = new T[size];
}
// Push method (adds a value to the stack)
public void Push(T frame)
{
// Pointer overflow check omitted for simplicity
this.frames[pointer++] = frame;
}
// Pop method (removes a value from the stack)
public T Pop()
{
// Pointer underflow check omitted for simplicity
return this.frames[--pointer];
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?