单利模式,堆栈,队列

单利实例--------------
using System;
using System.Collections.Generic;
using System.Text;
namespace WindowsApplication1
{
    public class Test
    {
        private static Test test;
        private Test(){
        }
       public static Test jia()      {
            if (test == null)  {
                test = new Test();
            }
            return test;
        }
    }
}
特点:
1>构造方法私有private 使别的类无法实例化。
2>有一个静态属性,类型是本身类。
3> 由一个静态的方法,返回值使类型使本身类。

堆栈实例-----------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
    class Program   {
        public static void Main(String[] args)  {
            Stack<String> s = new Stack<String>();
            s.Push("aaaaaa");
            s.Push("bbbbbb");
            s.Push("cccc");
            s.Push("ddddd");
            s.Push("eeeeee");
            System.Console.WriteLine("==========堆栈的内容=================\n");
            System.Console.WriteLine("s.size====" + s.Count);//5个
            System.Console.WriteLine("last is ====" + s.Last());
            System.Console.WriteLine("First is ====" + s.First());
            System.Console.WriteLine("s.pop ========="+s.Pop().ToString());
            System.Console.WriteLine("pop 后的数据-------------------");
            System.Console.WriteLine("s.size====" + s.Count);
            System.Console.WriteLine("s.last is ====" + s.Last());
            System.Console.WriteLine("s.First is ====" + s.First());

            System.Console.WriteLine("peek  is ====" + s.Peek());
            System.Console.WriteLine("反转后的First is ====" + s.Reverse().First());
            System.Console.WriteLine("\n\n==========队列的内容================\n");
            Queue<String> q = new Queue<String>();
            q.Enqueue("aaaaaa");
            q.Enqueue("bbbbb");
            q.Enqueue("cccccc");
            q.Enqueue("ddddddd");
            q.Enqueue("eeeeeee");
            System.Console.WriteLine("q size ========"+q.Count);
            System.Console.WriteLine("q.first ========="+q.First());
            System.Console.WriteLine("q.last =========" + q.Last());
       }
    }
}

输出结果-------------------------
            //==========堆栈的内容=================
            //s.size====5
            //last is ====aaaaaa
            //First is ====eeeeee
            //s.pop =========eeeeee
            //pop 后的数据-------------------
            //s.size====4
            //s.last is ====aaaaaa
            //s.First is ====ddddd
            //peek  is ====ddddd
            //反转后的First is ====aaaaaa

            //==========队列的内容================
            //q size ========5
            //q.first =========aaaaaa
            //q.last =========eeeeeee

 

 

堆栈,队列结论:堆栈先进后出,队列先进先出。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值