zoukankan      html  css  js  c++  java
  • 栈和队列(Stack and Queue)

    栈,先进后出,像桶一样,先放进去,最后才出来。

    队列,先进先出,就像管道一样,自来水管道,先进先出

    View Code
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;
    
    namespace StackTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] iArrary = new int[] { 1, 13, 3, 3, 6, 10, 10 };
                StackLearn(iArrary);
                QueueLearn(iArrary);
            }
    
            private static void StackLearn(int[] array)
            {
                Console.WriteLine("Stack");
                Stack stack = new Stack();
                foreach (int num in array)
                {
                    stack.Push(num);
                }
    
                for (int i = 0; i < array.Length; i++)
                {
                    Console.WriteLine((Int32)stack.Pop());
                }
            }
    
            private static void QueueLearn(int[] array)
            {
                Console.WriteLine("Queue");
                Queue queue = new Queue();
                foreach (int num in array)
                {
                    queue.Enqueue(num);
                }
    
                for (int i = 0; i < array.Length; i++)
                {
                    Console.WriteLine(queue.Dequeue());
                }
            }
        }
    }
  • 相关阅读:
    面向对象和面向过程的区别
    k-means算法
    win10系统下安装mysql
    python并发编程之多进程
    操作系统的概念
    前端基础之html
    聚类分析
    决策树
    Mysql
    SQL练习题
  • 原文地址:https://www.cnblogs.com/binyao/p/3054790.html
Copyright © 2011-2022 走看看