当前位置:网站首页>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!");
}
}
}
边栏推荐
- Swift bit operation exercise
- Analysis of the influence of voltage loop on PFC system performance
- 【习题六】【数据库原理】
- Summary of error prone knowledge points: Calculation of define s (x) 3*x*x+1.
- Kung Fu pays off, and learning is done
- Comprehensive evaluation of double chain notes · Siyuan notes: advantages, disadvantages and evaluation
- Sword finger offer04 Search in two-dimensional array [medium]
- 【习题五】【数据库原理】
- Xctf mobile--rememberother problem solving
- 剑指Offer03. 数组中重复的数字【简单】
猜你喜欢

【数据库原理复习题】

T430 toss and install OS majave 10.14

Node. Js: use of express + MySQL

Solve the problem of VI opening files with ^m at the end

最新版盲盒商城thinkphp+uniapp

Huffman coding experiment report

Seven second order ladrc-pll structure design of active disturbance rejection controller

Sword finger offer05 Replace spaces

【数据挖掘复习题】

剑指Offer06. 从尾到头打印链表
随机推荐
初入职场,如何快速脱颖而出?
Airflow installation jump pit
Flinksql can directly create tables and read MySQL or Kafka data on the client side, but how can it automatically flow and calculate?
最新版抽奖盲盒运营版
Openstack node address change
Node. Js: use of express + MySQL
Swift5.7 extend some to generic parameters
Redhat5 installing socket5 proxy server
Powerful avatar making artifact wechat applet
Quickly learn member inner classes and local inner classes
【数据库原理复习题】
Two solutions of leetcode101 symmetric binary tree (recursion and iteration)
ImportError: No module named examples. tutorials. mnist
【R】【密度聚类、层次聚类、期望最大化聚类】
Swift return type is a function of function
Eureka self protection
Apache Mina开发手册
最新版盲盒商城thinkphp+uniapp
Glide question you cannot start a load for a destroyed activity
Dix règles de travail