当前位置:网站首页>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!");
}
}
}
边栏推荐
- Alibaba is bigger than sending SMS (user microservice - message microservice)
- 公纵号发送提示信息(用户微服务--消息微服务)
- Quick learning 1.8 front and rear interfaces
- It feels great to know you learned something, isn‘t it?
- Togaf certification self-study classic v2.0
- Eureka自我保护
- 【数据库原理复习题】
- Sword finger offer06 Print linked list from end to end
- 十条职场规则
- 2021 autumn Information Security Experiment 1 (password and hiding technology)
猜你喜欢
【R】【密度聚类、层次聚类、期望最大化聚类】
Method overloading and rewriting
【综合题】【数据库原理】
Grid connection - Analysis of low voltage ride through and island coexistence
剑指Offer05. 替换空格
idea将web项目打包成war包并部署到服务器上运行
Cache penetration and bloom filter
Drop down refresh conflicts with recyclerview sliding (swiperefreshlayout conflicts with recyclerview sliding)
Eureka自我保护
studio All flavors must now belong to a named flavor dimension. Learn more
随机推荐
Take you to the installation and simple use tutorial of the deveco studio compiler of harmonyos to create and run Hello world?
Export the entire Oracle Database
Two solutions of leetcode101 symmetric binary tree (recursion and iteration)
Integer case study of packaging
2021 autumn Information Security Experiment 1 (password and hiding technology)
Application of ncnn neural network computing framework in orange school orangepi 3 lts development board
Sword finger offer07 Rebuild binary tree
【習題五】【數據庫原理】
Day 1 of kotlin learning: simple built-in types of kotlin
It feels great to know you learned something, isn‘t it?
Openstack node address change
电压环对 PFC 系统性能影响分析
Powerful avatar making artifact wechat applet
Sword finger offer10- I. Fibonacci sequence
Summary of error prone knowledge points: Calculation of define s (x) 3*x*x+1.
Dix règles de travail
Application of ncnn Neural Network Computing Framework in Orange Pi 3 Lts Development Board
Alibaba is bigger than sending SMS (user microservice - message microservice)
[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
Xctf mobile--app2 problem solving