Chapter3 Stacks and Queues 数据结构课件 入门者必备 第三章课件精品.pptVIP

  • 2
  • 0
  • 约1.58万字
  • 约 46页
  • 2017-02-02 发布于江苏
  • 举报

Chapter3 Stacks and Queues 数据结构课件 入门者必备 第三章课件精品.ppt

3.4.2 Terms Front——The end of a list that elements can only be deleted, denoted by front-pointer f. Rear——The end of a list that elements can only be added, denoted by rear-pointer r. Enqueue——To insert an element at the end of a queue. Dequeue——To delete the first element of a queue. 3.4.3 ADT ADT Queue { Data Objects: D={ ai | ai∈ ElemSet, i=1, 2, …, n, n ≥ 0 } Data Relationships: R1={ai-1, ai | ai-1, ai∈D, i=2, …, n} Assume that a1 is the front and an is the rear. Elementary Processes: InitQueue ( Q ) result: An empty queue Q constructed. DestroyQueue ( Q ) condition: Queue Q exists. result: Queue Q destroyed. ClearQueue ( Q ) condition: Queue Q exists. result: Queue Q reset to vacancy. QueueEmpty ( Q ) condition: Queue Q exists. result: Return true if queue Q is empty, or return false. QueueLength ( Q ) condition: Queue Q exists. result: Return the number of elements in queue Q. GetHead ( Q, e ) condition: Queue Q exists and is nonempty. result: Return the front of Q by e. EnQueue ( Q, e ) condition: Queue Q exists. result: Element e is inserted as the new rear of Q. DeQueue ( Q, e ) condition: Queue Q exists and is nonempty. result: The front of Q is deleted and returned by e. } ADT Queue 3.4.4 Representation and Implementation Like stacks, queues also have two storage forms: sequential and linked. Here we shall develop an implementation for queues based on array. The queue space is supplied by an array q[M] with the initialized condition f = r = -1. f and r will change when the operation of Dequeue or Enqueue occurs. Ex: given a queue q[3] 2 1 0 Empty queue f = r = -1 c b a Enqueue a,b,c f = 0, r = 2 Full queue 2 1 0 c b Dequeue a, f = 1, r = 2 Another Enqueue will lead to an illusive

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档