Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 1
Lecture 29
Log into Linux. Copy files on csserver from
/home/hwang/cs215/lecture29/*.*
Reminder: Project 5 and Homework 7 are due
- n Wednesday.
Questions?
Lecture 29 Log into Linux. Copy files on csserver from - - PowerPoint PPT Presentation
Lecture 29 Log into Linux. Copy files on csserver from /home/hwang/cs215/lecture29/*.* Reminder: Project 5 and Homework 7 are due on Wednesday. Questions? Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 1
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 1
Log into Linux. Copy files on csserver from
Reminder: Project 5 and Homework 7 are due
Questions?
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 2
Stacks applications
Balanced parentheses Arithmetic expression evaluation
Queue applications
Radix sort - this application is not in the textbook
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 3
Consider strings consisting of left and right
Some examples of balanced parentheses:
Some examples of unbalanced parentheses:
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 4
We want to write a function IsBalanced that
The basic idea is that we scan the string from
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 5
In particular, a right parenthesis matches the
The basic algorithm is:
Complete file parens.cpp
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 6
A fully-parenthesized numeric expression is
For this example, we will assume that the
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 7
We want to write a function ReadAndEvaluate
The main idea is that the right parentheses
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 8
When a right parenthesis is seen, then the
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 9
The basic algorithm is
Complete file calc.cpp
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 10
The function EvaluateStackTops receives and
Note that the top of the operand stack is the
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 11
The basic algorithm is
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 12
In the early days of computing, data were
Suppose all numbers are positive and have two
Pass 0: Look at the ones (i.e. rightmost) digit,
Repeat with the tens digit. At the end the cards
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 13
The "trick" can be seen by considering the last
All numbers in a particular bin ended up in
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 14
The algorithm relies on the numbers in a bin
Generalize this process to d-digit numbers with
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 15
We want to write a function RadixSort that
The numbers are distributed from the vector to
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 16
The basic algorithm is
Complete file radixsort.cpp
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 17
The Distribute function receives the vector,
The basic algorithm is
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 18
The Collect function receives and passes back
The basic algorithm is
Monday, November 1 CS 215 Fundamentals of Programming II - Lecture 29 19
Radix sort is very fast. It is linear in the maximum
However, it has limited applicability. Need to know
Need a finite number of "digit" values, since there is a
Takes up twice as much space. Every number must
Generally only used for a relatively small number of