当前位置:网站首页>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!");
}
}
}
边栏推荐
- Project video based on Linu development
- Seven second order ladrc-pll structure design of active disturbance rejection controller
- 自抗扰控制器七-二阶 LADRC-PLL 结构设计
- CNN MNIST handwriting recognition
- ImportError: No module named examples. tutorials. mnist
- 双链笔记·思源笔记综合评测:优点、缺点、评价
- Harmonic current detection based on synchronous coordinate transformation
- Swift bit operation exercise
- Comprehensive evaluation of double chain notes · Siyuan notes: advantages, disadvantages and evaluation
- [Exercice 5] [principe de la base de données]
猜你喜欢
Cache penetration and bloom filter
最新版抽奖盲盒运营版
Eureka自我保护
Solve the problem of VI opening files with ^m at the end
Xctf mobile--rememberother problem solving
剑指Offer10- I. 斐波那契数列
Swift bit operation exercise
Use Tencent cloud IOT platform to connect custom esp8266 IOT devices (realized by Tencent continuous control switch)
公纵号发送提示信息(用户微服务--消息微服务)
Drop down refresh conflicts with recyclerview sliding (swiperefreshlayout conflicts with recyclerview sliding)
随机推荐
基于同步坐标变换的谐波电流检测
Record your vulnhub breakthrough record
阿里 & 蚂蚁自研 IDE
TOGAF认证自学宝典V2.0
Application of ncnn neural network computing framework in orange school orangepi 3 lts development board
Eureka自我保护
Application of ncnn Neural Network Computing Framework in Orange Pi 3 Lts Development Board
如何在微信小程序中获取用户位置?
Xctf mobile--rememberother problem solving
启用MemCached的SASL认证
Brief introduction to mvcc
Four problems and isolation level of MySQL concurrency
Sword finger offer10- I. Fibonacci sequence
Do you feel like you've learned something and forgotten it?
Node.js: express + MySQL的使用
Quickly learn member inner classes and local inner classes
Exploration of sqoop1.4.4 native incremental import feature
Analysis of the influence of voltage loop on PFC system performance
idea将web项目打包成war包并部署到服务器上运行
ImportError: No module named examples. tutorials. mnist