当前位置:网站首页>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!");
}
}
}
边栏推荐
- Pytext training times error: typeerror:__ init__ () got an unexpected keyword argument 'serialized_ options'
- Togaf certification self-study classic v2.0
- Analysis of the influence of voltage loop on PFC system performance
- Eureka自我保护
- Swift bit operation exercise
- Sword finger offer14 the easiest way to cut rope
- Oh my Zsh + TMUX installation
- Sword finger offer06 Print linked list from end to end
- Detailed explanation of the most complete constraintlayout in history
- Airflow installation jump pit
猜你喜欢

01 three solutions to knapsack problem (greedy dynamic programming branch gauge)

Cache penetration and bloom filter

Low code platform international multilingual (I18N) technical solution

Differences between initial, inherit, unset, revert and all

【计网】第三章 数据链路层(2)流量控制与可靠传输、停止等待协议、后退N帧协议(GBN)、选择重传协议(SR)

With pictures and texts, summarize the basic review of C language in detail, so that all kinds of knowledge points are clear at a glance?

Take you to the installation and simple use tutorial of the deveco studio compiler of harmonyos to create and run Hello world?

(最新版) Wifi分销多开版+安装框架

Eureka自我保护

Sword finger offer06 Print linked list from end to end
随机推荐
【ArcGIS自定义脚本工具】矢量文件生成扩大矩形面要素
Attack and defense world mobile--ph0en1x-100
Ali & ant self developed IDE
剑指Offer10- I. 斐波那契数列
Flinksql can directly create tables and read MySQL or Kafka data on the client side, but how can it automatically flow and calculate?
【数据库原理及应用教程(第4版|微课版)陈志泊】【SQLServer2012综合练习】
Method overloading and rewriting
How to stand out quickly when you are new to the workplace?
Tianyi ty1208-z brush machine detailed tutorial (free to remove)
Social community forum app ultra-high appearance UI interface
Project video based on Linu development
剑指Offer05. 替换空格
Do you feel like you've learned something and forgotten it?
Enter the length of three sides of the triangle through the user, and calculate the area of the triangle, where the length is a real number
Exploration of sqoop1.4.4 native incremental import feature
启用MemCached的SASL认证
Seven second order ladrc-pll structure design of active disturbance rejection controller
Applet wxss introduction
Harmonic current detection based on synchronous coordinate transformation
剑指Offer03. 数组中重复的数字【简单】