zoukankan      html  css  js  c++  java
  • Queue

    Definition

    Queue: Abstract data type with the following operations

    • Enqueue(Key): adds key to collection
    • Key Dequeue(): removes and returns least recently-added key
    • Boolean Empty(): are there any elements?

    FIFO: First-In, First-Out

    Queue Implementation with Linked List

    • Enqueue: use List.PushBack
    • Dequeue: use List.TopFront and List.PopFront
    • Empty: use List.Empty

    Queue Implementation with Array

    Keep track of array as a circular array

    • Enqueue: write
    • Dequeue: read
    • Empty: read is equal to write

    Summary

    • Queues can be implemented with either a linked list(with tail pointer) or an array.
    • Each queue operation is O(1): Enqueue Dequeue Empty

    Distinction

    Array: a maximum size that queue can grow to(bounded).

    ​ Any amount that is unused is wasted space

    Queue: get arbitrarily large as long as there’s available memory

    ​ Downside is every element u have to pay for another pointer

  • 相关阅读:
    javaweb:Filter过滤器
    javaScript:高级
    javascript:基础
    Boostrao:轮播图
    Bootstrap案列:首页界面
    Bootstrap学习笔记
    javaweb:respone
    javaweb:jsp
    五、结构型模式--->07.享元模式
    五、结构型模式--->06.组合模式
  • 原文地址:https://www.cnblogs.com/Glov/p/13180947.html
Copyright © 2011-2022 走看看