当前位置:网站首页>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!");
}
}
}
边栏推荐
- How to get user location in wechat applet?
- Grid connection - Analysis of low voltage ride through and island coexistence
- [comprehensive question] [Database Principle]
- [judgment question] [short answer question] [Database Principle]
- Four problems and isolation level of MySQL concurrency
- Bert running error: attributeerror: module'tensorflow contrib. tpu' has no attribute 'InputPipelineConfig'
- 【習題五】【數據庫原理】
- Idea packages the web project into a war package and deploys it to the server to run
- 如何在微信小程序中获取用户位置?
- 最新版抽奖盲盒运营版
猜你喜欢

Togaf certification self-study classic v2.0

2021 autumn Information Security Experiment 1 (password and hiding technology)

Sword finger offer10- I. Fibonacci sequence

Use Tencent cloud IOT platform to connect custom esp8266 IOT devices (realized by Tencent continuous control switch)

Eureka自我保护

剑指Offer05. 替换空格

【数据库原理及应用教程(第4版|微课版)陈志泊】【第六章习题】

剑指Offer07. 重建二叉树

Swift bit operation exercise

Powerful avatar making artifact wechat applet
随机推荐
【习题六】【数据库原理】
【数据库原理及应用教程(第4版|微课版)陈志泊】【第六章习题】
剑指Offer05. 替换空格
Seven second order ladrc-pll structure design of active disturbance rejection controller
Xctf mobile--app2 problem solving
Sword finger offer03 Repeated numbers in the array [simple]
ORM use of node -serialize
初入职场,如何快速脱颖而出?
Four problems and isolation level of MySQL concurrency
Swift Error Handling
低代码平台国际化多语言(i18n)技术方案
Drop down refresh conflicts with recyclerview sliding (swiperefreshlayout conflicts with recyclerview sliding)
studio All flavors must now belong to a named flavor dimension. Learn more
[problem exploration and solution of one or more filters or listeners failing to start]
Two solutions of leetcode101 symmetric binary tree (recursion and iteration)
Approve iPad, which wants to use your icloud account
Deeply understand the mvcc mechanism of MySQL
Attack and defense world mobile--ph0en1x-100
Xctf mobile--app1 problem solving
并网-低电压穿越与孤岛并存分析