队列和栈的创建、赋值、取值和遍历
package com.zyc.scala
import scala.collection.mutable
/**
* Created with IntelliJ IDEA.
* Author: zyc2913@163.com
* Date: 2020/9/18 17:02
* Version: 1.0
* Description:Queue和Stack的创建、赋值、取值和遍历
*/
object StudyQueueAndStack {
def main(args: Array[String]): Unit = {
/**
*1. Queue:队列,是一种先进先出的数据结构
*/
//1.创建实例
val queue1 = new mutable.Queue[Int]()
val queue2 = mutable.Queue[Int]()
//2.赋值
queue1 += 1
queue1 += 2
queue1 += 3
queue1 += 4
queue1 += 5
queue1 += 6
//3.取值
val ints = queue1.dequeueAll(_ % 2 == 0) //取出queue1的偶数
println(ints) //控制台输出:ArrayBuffer(2, 4, 6)
println(queue1) //控制台输出:Queue(1, 3,