当前位置:网站首页>C graphical tutorial (Fourth Edition)_ Chapter 17 generic: genericsamplep315
C graphical tutorial (Fourth Edition)_ Chapter 17 generic: genericsamplep315
2022-07-03 12:52:00 【superfreak】
using System;
namespace Chapter17GenericSampleP315
{
class MyStack<T>
{
T[] StackArray;
int StackPointer = 0;
public void Push(T x)
{
if (!IsStackFull)
StackArray[StackPointer++] = x;
}
public T Pop()
{
return (!IsStackEmpty) ? StackArray[--StackPointer] : StackArray[0];
}
const int MaxStack = 10;
bool IsStackFull { get { return StackPointer >= MaxStack; } }
bool IsStackEmpty { get { return StackPointer <= 0; } }
public MyStack()
{
StackArray = new T[MaxStack];
}
public void Print()
{
for (int i = StackPointer - 1; i >= 0; i--)
{
Console.WriteLine("Value:{0}", StackArray[i]);
}
}
}
class Program
{
static void Main(string[] args)
{
MyStack<int> StackInt = new MyStack<int>();
MyStack<string> StackString= new MyStack<string>();
StackInt.Push(3);
StackInt.Push(5);
StackInt.Push(7);
StackInt.Push(9);
StackInt.Print();
StackString.Push("This is fun");
StackString.Push("Hi,there!");
StackString.Print();
Console.WriteLine("Hello World!");
}
}
}
边栏推荐
- 【习题六】【数据库原理】
- initial、inherit、unset、revert和all的区别
- idea将web项目打包成war包并部署到服务器上运行
- Sword finger offer14 the easiest way to cut rope
- Analysis of a music player Login Protocol
- Apache Mina开发手册
- ORM use of node -serialize
- Method overloading and rewriting
- Eureka self protection
- Grid connection - Analysis of low voltage ride through and island coexistence
猜你喜欢
Seven second order ladrc-pll structure design of active disturbance rejection controller
社交社区论坛APP超高颜值UI界面
The upward and downward transformation of polymorphism
【R】【密度聚类、层次聚类、期望最大化聚类】
Sword finger offer04 Search in two-dimensional array [medium]
Social community forum app ultra-high appearance UI interface
Powerful avatar making artifact wechat applet
The latest version of blind box mall thinkphp+uniapp
剑指Offer03. 数组中重复的数字【简单】
Day 1 of kotlin learning: simple built-in types of kotlin
随机推荐
【习题七】【数据库原理】
[exercise 6] [Database Principle]
Day 1 of kotlin learning: simple built-in types of kotlin
公纵号发送提示信息(用户微服务--消息微服务)
Deeply understand the mvcc mechanism of MySQL
如何在微信小程序中获取用户位置?
【習題七】【數據庫原理】
ORM use of node -serialize
低代码平台国际化多语言(i18n)技术方案
Node. Js: use of express + MySQL
【数据库原理及应用教程(第4版|微课版)陈志泊】【SQLServer2012综合练习】
Approve iPad, which wants to use your icloud account
【判断题】【简答题】【数据库原理】
阿里大于发送短信(用户微服务--消息微服务)
Alibaba is bigger than sending SMS (user microservice - message microservice)
【数据库原理复习题】
Tianyi ty1208-z brush machine detailed tutorial (free to remove)
【综合题】【数据库原理】
剑指Offer09. 用两个栈实现队列
[ManageEngine] the role of IP address scanning