Stack & Queue--Data Structure

来源:互联网 发布:淘宝卖家发布宝贝规格 编辑:程序博客网 时间:2024/05/21 08:02


Stack:

  Abstract data type with the following operations:

     Push(Key); Key Top(); Key Pop(); Boolean Empty().


Two form of Stack: 

  Stack with Array; Stack with Linked list.


Summary:

Stacks can be implemented with either an array or a linked list.

Each stack operation is O(1): Push, Pop, Top, Empty.

Stacks are occasionally known as LIFO queues.


Queue:

Abstract data type with the following operations:

  Enqueue(Key); Key Dequeue(); Boolean Empty()

FIFO.


Implementation with Linked List:

Enqueue: use List.PushBack

Dequeue: use List.TopFront and List.PopFront 

Empty: use List.Empty


Implementation with Array:



At this time, If operation of Enqueue cannot push "g" into the space,because we need to leave one space to recognize where is head and where is tail.


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.












原创粉丝点击