Linear Data Representation Queues and Stacks - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

Linear Data Representation Queues and Stacks

Description:

Construct an empty stack. Determine whether a stack S is empty. Push an item on the stack S ... Construct and empty queue. Determine whether queue Q is empty ... – PowerPoint PPT presentation

Number of Views:373
Avg rating:3.0/5.0
Slides: 7
Provided by: drjosep
Category:

less

Transcript and Presenter's Notes

Title: Linear Data Representation Queues and Stacks


1
Linear Data Representation- Queues and Stacks
  • There are collections of components arranged in a
    straight line.
  • With restrictions on where to add and delete from
    the structure, we have two special structures
    Stack and Queue
  • Both these ADT obey certain growth and decay
    laws
  • Both can be represented by
  • Linked list
  • Sequentially
  • Stacks are useful in processing nested data
    structures ( I.e algorithms in which programs
    call on subprograms like in sub-expressions

2
  • That is whenever a method calls on another
    method/or itself (recursive) stacks are natural.
  • Also algorithms that do parsing, evaluations and
    backtracking.
  • QUEUES
  • Can be used for regulating the processing of
    tasks in a system for fairness waiting queue
  • When regulating processes then algorithms like
    FIFO can be used
  • Queuing discipline can also be used in
    simulations and modeling

3
  • STACKS
  • Have two basic operations push and pop
  • Stacks are sometimes called LIFO
  • Is a sequence of items together with the
    following operations
  • Construct an empty stack
  • Determine whether a stack S is empty
  • Push an item on the stack S
  • Pop an item off S
  • Peek at the top item on S.
  • See figure 6.3

4
  • QUEUE is a sequence of items with the following
    operations
  • Construct and empty queue
  • Determine whether queue Q is empty
  • Insert in Q
  • Remove from Q
  • See fig 6.4
  • These operations can be carried out using both
    linked list and sequential representation of both
    ADTs ( stack and queue)
  • Example1 for the expression Ya2 (bc)2
    (de)2
  • This consist of parenthesis, brackets, and
    braces.

5
  • Example 2 Using ADT to evaluate Postfix
    expressions
  • Consider e x y- z
  • This is written as xy-z-
  • Implementation of a stack
  • Using sequential representation see program
    6.11
  • Using linked list representation see program
    6.12
  • Also see the use of stacks recursive calls -see
    programs 6.13 and figures 6.14 6.18.

6
  • Implementation of the Queue ADT
  • Using sequential representation
  • Use modular arithmetic to keep values in the
    range I.e xn ( 0, n-1
  • This causes the increasing rear of the queue to
    wrap around so front (front 1) n and rear
    (rear 1)n always wrap around.
  • See program 6.22
  • Using a linked list representation see program
    6.23
  • We should use linked lists when the size of the
    list is not known before hand and use an array
    otherwise.
Write a Comment
User Comments (0)
About PowerShow.com