zoukankan      html  css  js  c++  java
  • 1、一个简单实现栈的类

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace ConsoleApplication1
     7 {
     8     class Program
     9     {
    10         static void Main(string[] args)
    11         {
    12             Stack s = new Stack();
    13             s.Push(1);
    14             s.Push(10);
    15             s.Push(100);
    16             Console.WriteLine(s.Pop());
    17             Console.ReadLine();
    18             Console.WriteLine(s.Pop());
    19             Console.ReadLine();
    20             Console.WriteLine(s.Pop());
    21             Console.ReadLine();
    22 
    23         }
    24     }
    25 
    26     public class Stack
    27     {
    28         Entry top;
    29         public void Push(object data)
    30         {
    31             top = new Entry(top, data);  //入栈
    32         }
    33         public object Pop()
    34         {
    35             if (top == null) throw new InvalidOperationException();
    36             object result = top.data; top = top.next; return result;  //出栈
    37         }
    38         class Entry
    39         {
    40             public Entry next;
    41             public object data;
    42             public Entry(Entry next, object data)
    43             {
    44                 this.next = next; //将当前值赋值给下一个
    45                 this.data = data; //新值赋值给当前值
    46             }
    47         }
    48     } 
    49 
    50 }
  • 相关阅读:
    判断当前时间为星期几
    springboot+mysql数据源切换
    表单上传图片
    po,vo,bo,dto,dao解释
    生成电脑的SSH key
    单例模式
    事物的特性和隔离级别
    springAOP自定义注解讲解
    Spring依赖注入(DI)的三种方式
    redis持久化
  • 原文地址:https://www.cnblogs.com/xiaochun126/p/4164916.html
Copyright © 2011-2022 走看看