当前位置:网站首页>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!");
}
}
}
边栏推荐
- Redhat5 installing socket5 proxy server
- OpenStack节点地址改变
- 【数据库原理及应用教程(第4版|微课版)陈志泊】【SQLServer2012综合练习】
- GaN图腾柱无桥 Boost PFC(单相)七-PFC占空比前馈
- 剑指Offer03. 数组中重复的数字【简单】
- 最新版抽奖盲盒运营版
- The foreground uses RSA asymmetric security to encrypt user information
- [combinatorics] permutation and combination (multiple set permutation | multiple set full permutation | multiple set incomplete permutation all elements have a repetition greater than the permutation
- 低代码平台国际化多语言(i18n)技术方案
- Public and private account sending prompt information (user microservice -- message microservice)
猜你喜欢

公纵号发送提示信息(用户微服务--消息微服务)

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

【ArcGIS自定义脚本工具】矢量文件生成扩大矩形面要素

Sword finger offer14 the easiest way to cut rope

Powerful avatar making artifact wechat applet

(latest version) WiFi distribution multi format + installation framework

4. Wireless in vivo nano network: electromagnetic propagation model and key points of sensor deployment

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

Glide question you cannot start a load for a destroyed activity

【ManageEngine】IP地址扫描的作用
随机推荐
Apache Mina开发手册
公纵号发送提示信息(用户微服务--消息微服务)
Record your vulnhub breakthrough record
Brief introduction to mvcc
Attack and defense world mobile--ph0en1x-100
Kotlin notes - popular knowledge points asterisk (*)
[combinatorics] permutation and combination (the combination number of multiple sets | the repetition of all elements is greater than the combination number | the derivation of the combination number
Harmonic current detection based on synchronous coordinate transformation
Glide 4.6.1 API initial
Gan totem column bridgeless boost PFC (single phase) seven PFC duty cycle feedforward
Drop down refresh conflicts with recyclerview sliding (swiperefreshlayout conflicts with recyclerview sliding)
Project video based on Linu development
Sword finger offer14 the easiest way to cut rope
01 three solutions to knapsack problem (greedy dynamic programming branch gauge)
十條職場規則
ncnn神经网络计算框架在香橙派OrangePi 3 LTS开发板中的使用介绍
2021 autumn Information Security Experiment 1 (password and hiding technology)
如何在微信小程序中获取用户位置?
Nodejs+express+mysql realizes login function (including verification code)
十条职场规则