CIS 403503 Accelerated DataFile Structures - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

CIS 403503 Accelerated DataFile Structures

Description:

In this lecture, we will learn. Stack application: Prefix, infix, postfix. Queue ... Right-assocative. Input precedence. Stack precedence ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 17
Provided by: yanz
Category:

less

Transcript and Presenter's Notes

Title: CIS 403503 Accelerated DataFile Structures


1
CIS 403/503Accelerated Data-File Structures
  • Lecture 15
  • Queue

2
Objectives
  • In this lecture, we will learn
  • Stack application Prefix, infix, postfix
  • Queue

3
Stack Application
4
Mathematical Expression
  • Infix a b c
  • Postfix abc
  • Examples
  • (ab)c //abc
  • (abc)/de
  • ab-c/d
  • abcdef
  • a(bcd)/e
  • (bb-4ac)/(2a)

5
Infix-to-Postfix
  • Push operators onto a stack
  • Output operands to the postfix string
  • Example a b c
  • What about ab/cd

6
Infix-to-Postfix
  • Remove all operators on the stack that have the
    same or higher precedence
  • Example ab/cd
  • What about abc

7
Infix-to-Postfix
  • Right-assocative
  • Input precedence
  • Stack precedence
  • If the input precedence is lt stack precedence,
    pop the operator and write it to the postfix
  • If the input precedence is gt stack precedence,
    push the operator on the stack,

8
Infix-to-Postfix
  • and -
  • Input 1
  • Stack 1
  • Rank -1
  • , / and
  • Input 2
  • Stack 2
  • Rank -1
  • Input 4
  • Stack 3
  • Rank -1
  • (
  • Input 5
  • Stack -1
  • Rank 0
  • )
  • Input 0
  • Stack 0
  • Rank 0

9
Infix-to-Postfix
  • 3 (4 - 25)6
  • 5 (23)6

10
Queue
11
Overview
  • Queue
  • A data structure in which data are added to the
    back and removed from the front
  • FIFO/FCFS

12
STL Queue Operations
  • void push(const T item)
  • Insert item at the top
  • Postcondition new item at the back
  • void pop()
  • Remove the item from the front
  • Precondition queue is not empty
  • Postcondition queue has one less item
  • bool empty() const
  • Check if queue is empty
  • int size() const
  • Number of items in the queue
  • T front()
  • A reference to the front of the queue
  • Precondition queue is not empty
  • const T front() const
  • Constant reference

13
Example
  • includeltqueuegt
  • includeltiostreamgt
  • using namespace std
  • int main()
  • queueltintgt q
  • int i
  • for (i1 ilt5 i)
  • q.push(i)
  • cout ltlt Queue size " ltlt q.size() ltlt
    endl
  • cout ltlt Pop the queue" ltlt endl
  • while(!q.empty())
  • cout ltlt q.front() ltlt " "
  • q.pop()
  • cout ltlt endl

14
Example
  • includeltqueuegt
  • includeltiostreamgt
  • using namespace std
  • int main()
  • queueltintgt q
  • q.push(2)
  • q.push(3)
  • q.push(-1)
  • cout ltltq.top() ltlt endl
  • //change top to 4
  • q.front() 5
  • while(!q.empty())
  • cout ltlt q.front() ltlt " "
  • q.pop()

15
Summary
  • Stack application infix-to-postfix
  • Queue ADT

16
Possible Quiz Questions
  • Convert from infix to postfix
  • Stack operation in the design of infix-to-postfix
    conversion
  • Queue operations in STL
Write a Comment
User Comments (0)
About PowerShow.com