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:


Stack & Queue--Data Structure

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.

Stack & Queue--Data Structure

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.


Stack & Queue--Data Structure




Stack & Queue--Data Structure






相关文章: