zoukankan      html  css  js  c++  java
  • 栈(C#数据结构学习二)

     1using System;
     2using System.Collections;
     3using System.Collections.Generic;
     4using System.Text;
     5
     6namespace soloDataStruct
     7{
     8   public class Mystack<T>
     9    {
    10       private T[] stackarray;
    11       private int maxSize;
    12       private int top;
    13       public Mystack(int s)
    14       {
    15           maxSize = s;
    16           stackarray=new T[maxSize];
    17           top = -1;
    18       }

    19       public void Push(T data)
    20       {
    21           if (top == maxSize - 1)
    22               Console.WriteLine("out of space!");
    23           stackarray[++top] = data;
    24       }

    25       public T Pop()
    26       {
    27           if (top == -1)
    28               Console.WriteLine("out of space!");
    29           return stackarray[top--];
    30
    31       }

    32       public T GetTop()
    33       {
    34           if (top == -1)
    35               Console.WriteLine("Stack is empty ");
    36               return stackarray[top];
    37       }

    38       public bool ifemptystack()
    39       {
    40           return top == -1;
    41
    42       }

    43
    44    }

    45
    46    class test
    47    {
    48        static void Main(string[] args)
    49        {
    50            Mystack<string> mystack=new Mystack<string>(5);
    51            mystack.Push("a");
    52            mystack.Push("b");
    53            mystack.Push("c");
    54            mystack.Push("d");
    55           Console.WriteLine("Stack poped data is {0}", mystack.Pop());
    56           Console.WriteLine("Stack poped data is {0}", mystack.Pop());
    57           Console.ReadLine();
    58
    59        }

    60    }

    61}

    62
    63
  • 相关阅读:
    解决“google快照无法打开”的简单而有效的方法~
    在Struts2里面嵌入Spring
    HDU
    设计模式大总结(二)
    Node.js入门笔记
    草图检索和识别[开源]
    2019-10-31-VisualStudio-断点调试详解
    2019-10-31-VisualStudio-断点调试详解
    2019-9-2-C#-设计模式-责任链
    2019-9-2-C#-设计模式-责任链
  • 原文地址:https://www.cnblogs.com/solo/p/594840.html
Copyright © 2011-2022 走看看