SlideShare a Scribd company logo
Learning Objectives
Gain some experience using dynamic data structures, which can
grow and shrink at execution time.
In this lab, you will use
Stacks
, and
Maps
.
Learn to iterate through a dynamic data structures
Setup
Set up your directory:
$ mkdir -p ~/cs180/lab14
$ cd ~/cs180/lab14
$ drjava &
Evaluator
Introduction
Reverse Polish notation (RPN) is a mathematical notation in
which every operator follows all of its operands, in contrast to
Polish notation, which puts the operator in the prefix position.
It is also known as postfix notation and is parenthesis-free as
long as operator arities are fixed. The description “Polish”
refers to the nationality of logician Jan Łukasiewicz, who
invented (prefix) Polish notation in the 1920s.
In reverse Polish notation the operators follow their operands;
for instance, to add 3 and 4, one would write
3 4 +
rather than
3 + 4
. If there are multiple operations, the operator is given
immediately after its second operand; so the expression written
3 − 4 + 5
in conventional notation would be written
3 4 − 5 +
in RPN: 4 is first subtracted from 3, then 5 added to it.
An advantage of RPN is that it obviates the need for parentheses
that are required by infix notation. While
3 − 4 × 5
can also be written
3 − (4 × 5)
, that means something quite different from
(3 − 4) × 5
. In postfix, the former could be written
3 4 5 × −
, which unambiguously means
3 (4 5 ×) −
which reduces to
3 20 −
; the latter could be written
3 4 − 5 ×
(or
5 3 4 − ×
, if keeping similar formatting), which unambiguously means
(3 4 −) 5 ×
.
Despite the name, reverse Polish notation is not exactly the
reverse of Polish notation, for the operands of non-commutative
operations are still written in the conventional order (e.g.
÷ 6 3
in Polish notation and
6 3 ÷
in reverse Polish both evaluate to 2, whereas
3 6 ÷
; in reverse Polish notation would evaluate to ½).
Example
The infix expression
5 + ((1 + 2) × 4) − 3
can be written down like this in RPN:
5 1 2 + 4 × + 3 −
The expression is evaluated left-to-right, with the inputs
interpreted as shown in the following table (the Stack is the list
of values the algorithm is “keeping track of” after the Operation
given in the middle column has taken place):
Input
Operation
Stack
Comment
5
Push value
5
-
1
Push value
1,5
-
2
Push value
2,1,5
-
+
Add
3,5
Pop two values (1, 2) and push result (3)
4
Push value
4,3,5
-
x
Multiply
12,5
Pop two values (3, 4) and push result (12)
+
Add
17
Pop two values (5, 12) and push result (17)
3
Push value
3,17
-
-
Subtract
14
Pop two values (17, 3) and push result (14)
Result
14
-
Your Task
Now that we have explained the working of an RPN Calculator,
it is time to make one ourselves.
We will do that by using the
Stack
data structure, which is already implemented in the Java
libraries.
Use the push and pop functions as well as the constructor.
Implement a class
Evaluator
with a
static
class method
evaluate
that takes a
String
argument comprising an RPN expression and returns the
int
result.
Make sure to test your evaluator — pass a
String
argument to calls to
evaluate
to check the results.
Stats
Introduction
In computing, a hash table (such as a Java
HashMap
) is a data structure used to implement an associative structure
that maps
keys
to
values
.
A hash table uses a hash function to compute an index into an
array of buckets or slots, from which the correct value can be
found.
In a well-dimensioned hash table, the average cost (number of
instructions) for each lookup is independent of the number of
elements stored in the table.
Many hash table designs also allow arbitrary insertions and
deletions of key-value pairs, at constant average cost per
operation.
In some situations, hash tables turn out to be more efficient than
search trees or any other table lookup structure. For this reason,
they are widely used in many kinds of computer software,
particularly for associative arrays, database indexing, caches,
and sets.
Here is the Java documentation for
HashMap
:
http://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html
Creating a HashMap
To Create a HashMap in java, we first need to import the
required header files:
import
java.util.HashMap
;
import
java.util.Map
;
To Create a HashMap in java, we use the
HashMap
constructor.
HashMap
is a generic class, which means that we must indicate the types
of the keys and values it will use. For a map from
String
to
Integer
we use the constructor as follows:
Map
<
String
,Integer
>
map
=
new
HashMap
<
String
,Integer
>
(
)
;
The basic working of a
HashMap
used to track integer counts is:
Check if the element is present in the map.
If the element is present, increment its corresponding count.
If the element is not present, add the word to the map with its
corresponding count.
To look for an element in the map, use the method:
get()
For example, if we are looking for the word “the”:
Map
<
String
,Integer
>
map
=
new
HashMap
<
String
,Integer
>
(
)
;
String
word
=
"the"
;
Integer
count
=
map.
get
(
word
)
;
If the count in the above example is
null
, it simply means that the word doesn't exist in the map.
To add an element to the map, use the library function:
put()
:
map.
put
(
word, count
)
;
The arguments passed to the function
put
are the word (
String
) and count (
int
) which is the total number of times the number is seen. To
fetch the count of a given word, use the
get()
function.
Scenario
You work for an esteemed sports news website. The big story is
that the NBA is having a special all star league, in which teams
are assigned randomly before each game. The winner(s) of the
competition are the players who are in the most winning teams.
Your team has developed a way to organize a file so that your
reports come in faster than any other website.
File Format
Input file
The file is formatted as follows in which each line represents
one game: The first token is an integer that can be either
1
or
0
. It is
1
if the
first team
won and it is
0
if the
second team won
.
This token is followed by exactly five tokens representing the
player names of the first team (separated by spaces). After that,
the token
vs
token follows and finally five tokens for the player names of
the second team.
For example, this line means the second team with players
Prelich Murphy Wilkes Gall Greenberg
has won :
0 Chan Stine Neilson Curtis Kennedy vs Prelich Murphy Wilkes
Gall Greenberg
Your Task
Implement a class
Stats
with a
static
class method
wins
that reads lines of input from a
BufferedReader
and computes winner statistics for each of the players
mentioned in the input, by constructing a
HashMap
mapping the names of the players (
String
) to the number of wins (
Integer
) that player has accumulated, and returns the resulting
HashMap
.
Now, implement a
static
class method
winner
that iterates through a
HashMap
, such as returned by
wins
, returning the name of the player with the most wins (in the
case of a tie, return any such player).
Make sure to test your methods.
Ad

More Related Content

Similar to Learning ObjectivesGain some experience using dynamic data structu.docx (20)

C Interview Questions for Fresher
C Interview Questions for FresherC Interview Questions for Fresher
C Interview Questions for Fresher
Javed Ahmad
 
C interview Question and Answer
C interview Question and AnswerC interview Question and Answer
C interview Question and Answer
Jagan Mohan Bishoyi
 
C interview-questions-techpreparation
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparation
sonu sharma
 
C interview-questions-techpreparation
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparation
Kgr Sushmitha
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
Kevlin Henney
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo
JinTaek Seo
 
This first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docxThis first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docx
abhi353063
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
carliotwaycave
 
Php Learning show
Php Learning showPhp Learning show
Php Learning show
Gnugroup India
 
Python basics
Python basicsPython basics
Python basics
Hoang Nguyen
 
Python basics
Python basicsPython basics
Python basics
Harry Potter
 
Python basics
Python basicsPython basics
Python basics
Fraboni Ec
 
Python basics
Python basicsPython basics
Python basics
James Wong
 
Python basics
Python basicsPython basics
Python basics
Tony Nguyen
 
Python basics
Python basicsPython basics
Python basics
Luis Goldster
 
Python basics
Python basicsPython basics
Python basics
Young Alista
 
Morel, a data-parallel programming language
Morel, a data-parallel programming languageMorel, a data-parallel programming language
Morel, a data-parallel programming language
Julian Hyde
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
vsssuresh
 
Although people may be very accustomed to reading and understanding .docx
Although people may be very accustomed to reading and understanding .docxAlthough people may be very accustomed to reading and understanding .docx
Although people may be very accustomed to reading and understanding .docx
milissaccm
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
Muthuselvam RS
 
C Interview Questions for Fresher
C Interview Questions for FresherC Interview Questions for Fresher
C Interview Questions for Fresher
Javed Ahmad
 
C interview-questions-techpreparation
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparation
sonu sharma
 
C interview-questions-techpreparation
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparation
Kgr Sushmitha
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
Kevlin Henney
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo
JinTaek Seo
 
This first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docxThis first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docx
abhi353063
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
carliotwaycave
 
Morel, a data-parallel programming language
Morel, a data-parallel programming languageMorel, a data-parallel programming language
Morel, a data-parallel programming language
Julian Hyde
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
vsssuresh
 
Although people may be very accustomed to reading and understanding .docx
Although people may be very accustomed to reading and understanding .docxAlthough people may be very accustomed to reading and understanding .docx
Although people may be very accustomed to reading and understanding .docx
milissaccm
 

More from jesseniasaddler (20)

List and discuss five important criteria that a state must meet in.docx
List and discuss five important criteria that a state must meet in.docxList and discuss five important criteria that a state must meet in.docx
List and discuss five important criteria that a state must meet in.docx
jesseniasaddler
 
List and define the five traits included in the Big Five theory of p.docx
List and define the five traits included in the Big Five theory of p.docxList and define the five traits included in the Big Five theory of p.docx
List and define the five traits included in the Big Five theory of p.docx
jesseniasaddler
 
List and describe the six (6) parts of a speech.Describe.docx
List and describe the six (6) parts of a speech.Describe.docxList and describe the six (6) parts of a speech.Describe.docx
List and describe the six (6) parts of a speech.Describe.docx
jesseniasaddler
 
List 2 characteristics of each period listed below1-2. Renais.docx
List 2 characteristics of each period listed below1-2. Renais.docxList 2 characteristics of each period listed below1-2. Renais.docx
List 2 characteristics of each period listed below1-2. Renais.docx
jesseniasaddler
 
Linking or actionThe government opertaion many large parks.Many .docx
Linking or actionThe government opertaion many large parks.Many .docxLinking or actionThe government opertaion many large parks.Many .docx
Linking or actionThe government opertaion many large parks.Many .docx
jesseniasaddler
 
Limit responses to less than one page each using 12 pt. Time News Ro.docx
Limit responses to less than one page each using 12 pt. Time News Ro.docxLimit responses to less than one page each using 12 pt. Time News Ro.docx
Limit responses to less than one page each using 12 pt. Time News Ro.docx
jesseniasaddler
 
Limit responses to less than one page each using 12 pt. Time News .docx
Limit responses to less than one page each using 12 pt. Time News .docxLimit responses to less than one page each using 12 pt. Time News .docx
Limit responses to less than one page each using 12 pt. Time News .docx
jesseniasaddler
 
Likewise with each new investigative finding there will dependably b.docx
Likewise with each new investigative finding there will dependably b.docxLikewise with each new investigative finding there will dependably b.docx
Likewise with each new investigative finding there will dependably b.docx
jesseniasaddler
 
Lifelong Learning PlanIntroductionLife long learning is a concep.docx
Lifelong Learning PlanIntroductionLife long learning is a concep.docxLifelong Learning PlanIntroductionLife long learning is a concep.docx
Lifelong Learning PlanIntroductionLife long learning is a concep.docx
jesseniasaddler
 
Library Research AssignmentYou are new member of internal affairs .docx
Library Research AssignmentYou are new member of internal affairs .docxLibrary Research AssignmentYou are new member of internal affairs .docx
Library Research AssignmentYou are new member of internal affairs .docx
jesseniasaddler
 
Library Research AssignmentUse the library and other Web resources.docx
Library Research AssignmentUse the library and other Web resources.docxLibrary Research AssignmentUse the library and other Web resources.docx
Library Research AssignmentUse the library and other Web resources.docx
jesseniasaddler
 
Let U = {8, 9, 10, 11, 12, 13, 14}, .docx
Let U = {8, 9, 10, 11, 12, 13, 14}, .docxLet U = {8, 9, 10, 11, 12, 13, 14}, .docx
Let U = {8, 9, 10, 11, 12, 13, 14}, .docx
jesseniasaddler
 
Letter of CreditThe text describes problems exporters have with le.docx
Letter of CreditThe text describes problems exporters have with le.docxLetter of CreditThe text describes problems exporters have with le.docx
Letter of CreditThe text describes problems exporters have with le.docx
jesseniasaddler
 
Lets start this discussion by sharing public observations. Spend ti.docx
Lets start this discussion by sharing public observations. Spend ti.docxLets start this discussion by sharing public observations. Spend ti.docx
Lets start this discussion by sharing public observations. Spend ti.docx
jesseniasaddler
 
Lets look to the 20th century portion of the Modules for this Discu.docx
Lets look to the 20th century portion of the Modules for this Discu.docxLets look to the 20th century portion of the Modules for this Discu.docx
Lets look to the 20th century portion of the Modules for this Discu.docx
jesseniasaddler
 
Leiningers Theory of Cultural Care Diversity and Universality.docx
Leiningers Theory of Cultural Care Diversity and Universality.docxLeiningers Theory of Cultural Care Diversity and Universality.docx
Leiningers Theory of Cultural Care Diversity and Universality.docx
jesseniasaddler
 
Length PowerPoint presentation with 10 - 15 slides (not including.docx
Length PowerPoint presentation with 10 - 15 slides (not including.docxLength PowerPoint presentation with 10 - 15 slides (not including.docx
Length PowerPoint presentation with 10 - 15 slides (not including.docx
jesseniasaddler
 
Length PowerPoint presentation with 15 slides (not including ti.docx
Length PowerPoint presentation with 15 slides (not including ti.docxLength PowerPoint presentation with 15 slides (not including ti.docx
Length PowerPoint presentation with 15 slides (not including ti.docx
jesseniasaddler
 
Length is 3-4 pages not including References. references should be a.docx
Length is 3-4 pages not including References. references should be a.docxLength is 3-4 pages not including References. references should be a.docx
Length is 3-4 pages not including References. references should be a.docx
jesseniasaddler
 
Length1,000 words maximumThere are five general ethical t.docx
Length1,000 words maximumThere are five general ethical t.docxLength1,000 words maximumThere are five general ethical t.docx
Length1,000 words maximumThere are five general ethical t.docx
jesseniasaddler
 
List and discuss five important criteria that a state must meet in.docx
List and discuss five important criteria that a state must meet in.docxList and discuss five important criteria that a state must meet in.docx
List and discuss five important criteria that a state must meet in.docx
jesseniasaddler
 
List and define the five traits included in the Big Five theory of p.docx
List and define the five traits included in the Big Five theory of p.docxList and define the five traits included in the Big Five theory of p.docx
List and define the five traits included in the Big Five theory of p.docx
jesseniasaddler
 
List and describe the six (6) parts of a speech.Describe.docx
List and describe the six (6) parts of a speech.Describe.docxList and describe the six (6) parts of a speech.Describe.docx
List and describe the six (6) parts of a speech.Describe.docx
jesseniasaddler
 
List 2 characteristics of each period listed below1-2. Renais.docx
List 2 characteristics of each period listed below1-2. Renais.docxList 2 characteristics of each period listed below1-2. Renais.docx
List 2 characteristics of each period listed below1-2. Renais.docx
jesseniasaddler
 
Linking or actionThe government opertaion many large parks.Many .docx
Linking or actionThe government opertaion many large parks.Many .docxLinking or actionThe government opertaion many large parks.Many .docx
Linking or actionThe government opertaion many large parks.Many .docx
jesseniasaddler
 
Limit responses to less than one page each using 12 pt. Time News Ro.docx
Limit responses to less than one page each using 12 pt. Time News Ro.docxLimit responses to less than one page each using 12 pt. Time News Ro.docx
Limit responses to less than one page each using 12 pt. Time News Ro.docx
jesseniasaddler
 
Limit responses to less than one page each using 12 pt. Time News .docx
Limit responses to less than one page each using 12 pt. Time News .docxLimit responses to less than one page each using 12 pt. Time News .docx
Limit responses to less than one page each using 12 pt. Time News .docx
jesseniasaddler
 
Likewise with each new investigative finding there will dependably b.docx
Likewise with each new investigative finding there will dependably b.docxLikewise with each new investigative finding there will dependably b.docx
Likewise with each new investigative finding there will dependably b.docx
jesseniasaddler
 
Lifelong Learning PlanIntroductionLife long learning is a concep.docx
Lifelong Learning PlanIntroductionLife long learning is a concep.docxLifelong Learning PlanIntroductionLife long learning is a concep.docx
Lifelong Learning PlanIntroductionLife long learning is a concep.docx
jesseniasaddler
 
Library Research AssignmentYou are new member of internal affairs .docx
Library Research AssignmentYou are new member of internal affairs .docxLibrary Research AssignmentYou are new member of internal affairs .docx
Library Research AssignmentYou are new member of internal affairs .docx
jesseniasaddler
 
Library Research AssignmentUse the library and other Web resources.docx
Library Research AssignmentUse the library and other Web resources.docxLibrary Research AssignmentUse the library and other Web resources.docx
Library Research AssignmentUse the library and other Web resources.docx
jesseniasaddler
 
Let U = {8, 9, 10, 11, 12, 13, 14}, .docx
Let U = {8, 9, 10, 11, 12, 13, 14}, .docxLet U = {8, 9, 10, 11, 12, 13, 14}, .docx
Let U = {8, 9, 10, 11, 12, 13, 14}, .docx
jesseniasaddler
 
Letter of CreditThe text describes problems exporters have with le.docx
Letter of CreditThe text describes problems exporters have with le.docxLetter of CreditThe text describes problems exporters have with le.docx
Letter of CreditThe text describes problems exporters have with le.docx
jesseniasaddler
 
Lets start this discussion by sharing public observations. Spend ti.docx
Lets start this discussion by sharing public observations. Spend ti.docxLets start this discussion by sharing public observations. Spend ti.docx
Lets start this discussion by sharing public observations. Spend ti.docx
jesseniasaddler
 
Lets look to the 20th century portion of the Modules for this Discu.docx
Lets look to the 20th century portion of the Modules for this Discu.docxLets look to the 20th century portion of the Modules for this Discu.docx
Lets look to the 20th century portion of the Modules for this Discu.docx
jesseniasaddler
 
Leiningers Theory of Cultural Care Diversity and Universality.docx
Leiningers Theory of Cultural Care Diversity and Universality.docxLeiningers Theory of Cultural Care Diversity and Universality.docx
Leiningers Theory of Cultural Care Diversity and Universality.docx
jesseniasaddler
 
Length PowerPoint presentation with 10 - 15 slides (not including.docx
Length PowerPoint presentation with 10 - 15 slides (not including.docxLength PowerPoint presentation with 10 - 15 slides (not including.docx
Length PowerPoint presentation with 10 - 15 slides (not including.docx
jesseniasaddler
 
Length PowerPoint presentation with 15 slides (not including ti.docx
Length PowerPoint presentation with 15 slides (not including ti.docxLength PowerPoint presentation with 15 slides (not including ti.docx
Length PowerPoint presentation with 15 slides (not including ti.docx
jesseniasaddler
 
Length is 3-4 pages not including References. references should be a.docx
Length is 3-4 pages not including References. references should be a.docxLength is 3-4 pages not including References. references should be a.docx
Length is 3-4 pages not including References. references should be a.docx
jesseniasaddler
 
Length1,000 words maximumThere are five general ethical t.docx
Length1,000 words maximumThere are five general ethical t.docxLength1,000 words maximumThere are five general ethical t.docx
Length1,000 words maximumThere are five general ethical t.docx
jesseniasaddler
 
Ad

Recently uploaded (20)

pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)
GS Virdi
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdfAPM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
Association for Project Management
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
How to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo SlidesHow to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo Slides
Celine George
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
Rococo versus Neoclassicism. The artistic styles of the 18th century
Rococo versus Neoclassicism. The artistic styles of the 18th centuryRococo versus Neoclassicism. The artistic styles of the 18th century
Rococo versus Neoclassicism. The artistic styles of the 18th century
Gema
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
Grade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable WorksheetGrade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable Worksheet
Sritoma Majumder
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)
GS Virdi
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
How to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo SlidesHow to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo Slides
Celine George
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
Rococo versus Neoclassicism. The artistic styles of the 18th century
Rococo versus Neoclassicism. The artistic styles of the 18th centuryRococo versus Neoclassicism. The artistic styles of the 18th century
Rococo versus Neoclassicism. The artistic styles of the 18th century
Gema
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
Grade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable WorksheetGrade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable Worksheet
Sritoma Majumder
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
Ad

Learning ObjectivesGain some experience using dynamic data structu.docx

  • 1. Learning Objectives Gain some experience using dynamic data structures, which can grow and shrink at execution time. In this lab, you will use Stacks , and Maps . Learn to iterate through a dynamic data structures Setup Set up your directory: $ mkdir -p ~/cs180/lab14 $ cd ~/cs180/lab14 $ drjava & Evaluator Introduction Reverse Polish notation (RPN) is a mathematical notation in which every operator follows all of its operands, in contrast to Polish notation, which puts the operator in the prefix position. It is also known as postfix notation and is parenthesis-free as long as operator arities are fixed. The description “Polish” refers to the nationality of logician Jan Łukasiewicz, who invented (prefix) Polish notation in the 1920s. In reverse Polish notation the operators follow their operands; for instance, to add 3 and 4, one would write 3 4 + rather than 3 + 4 . If there are multiple operations, the operator is given immediately after its second operand; so the expression written 3 − 4 + 5 in conventional notation would be written
  • 2. 3 4 − 5 + in RPN: 4 is first subtracted from 3, then 5 added to it. An advantage of RPN is that it obviates the need for parentheses that are required by infix notation. While 3 − 4 × 5 can also be written 3 − (4 × 5) , that means something quite different from (3 − 4) × 5 . In postfix, the former could be written 3 4 5 × − , which unambiguously means 3 (4 5 ×) − which reduces to 3 20 − ; the latter could be written 3 4 − 5 × (or 5 3 4 − × , if keeping similar formatting), which unambiguously means (3 4 −) 5 × . Despite the name, reverse Polish notation is not exactly the reverse of Polish notation, for the operands of non-commutative operations are still written in the conventional order (e.g. ÷ 6 3 in Polish notation and 6 3 ÷ in reverse Polish both evaluate to 2, whereas 3 6 ÷ ; in reverse Polish notation would evaluate to ½). Example The infix expression 5 + ((1 + 2) × 4) − 3 can be written down like this in RPN: 5 1 2 + 4 × + 3 −
  • 3. The expression is evaluated left-to-right, with the inputs interpreted as shown in the following table (the Stack is the list of values the algorithm is “keeping track of” after the Operation given in the middle column has taken place): Input Operation Stack Comment 5 Push value 5 - 1 Push value 1,5 - 2 Push value 2,1,5 - + Add 3,5 Pop two values (1, 2) and push result (3) 4 Push value 4,3,5 - x Multiply 12,5 Pop two values (3, 4) and push result (12) + Add 17 Pop two values (5, 12) and push result (17)
  • 4. 3 Push value 3,17 - - Subtract 14 Pop two values (17, 3) and push result (14) Result 14 - Your Task Now that we have explained the working of an RPN Calculator, it is time to make one ourselves. We will do that by using the Stack data structure, which is already implemented in the Java libraries. Use the push and pop functions as well as the constructor. Implement a class Evaluator with a static class method evaluate that takes a String argument comprising an RPN expression and returns the int result. Make sure to test your evaluator — pass a String argument to calls to evaluate to check the results.
  • 5. Stats Introduction In computing, a hash table (such as a Java HashMap ) is a data structure used to implement an associative structure that maps keys to values . A hash table uses a hash function to compute an index into an array of buckets or slots, from which the correct value can be found. In a well-dimensioned hash table, the average cost (number of instructions) for each lookup is independent of the number of elements stored in the table. Many hash table designs also allow arbitrary insertions and deletions of key-value pairs, at constant average cost per operation. In some situations, hash tables turn out to be more efficient than search trees or any other table lookup structure. For this reason, they are widely used in many kinds of computer software, particularly for associative arrays, database indexing, caches, and sets. Here is the Java documentation for HashMap : http://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html Creating a HashMap To Create a HashMap in java, we first need to import the required header files: import java.util.HashMap ;
  • 6. import java.util.Map ; To Create a HashMap in java, we use the HashMap constructor. HashMap is a generic class, which means that we must indicate the types of the keys and values it will use. For a map from String to Integer we use the constructor as follows: Map < String ,Integer > map = new HashMap < String ,Integer > ( ) ; The basic working of a HashMap used to track integer counts is: Check if the element is present in the map.
  • 7. If the element is present, increment its corresponding count. If the element is not present, add the word to the map with its corresponding count. To look for an element in the map, use the method: get() For example, if we are looking for the word “the”: Map < String ,Integer > map = new HashMap < String ,Integer > ( ) ; String word = "the" ; Integer count = map. get
  • 8. ( word ) ; If the count in the above example is null , it simply means that the word doesn't exist in the map. To add an element to the map, use the library function: put() : map. put ( word, count ) ; The arguments passed to the function put are the word ( String ) and count ( int ) which is the total number of times the number is seen. To fetch the count of a given word, use the get() function. Scenario You work for an esteemed sports news website. The big story is that the NBA is having a special all star league, in which teams are assigned randomly before each game. The winner(s) of the competition are the players who are in the most winning teams. Your team has developed a way to organize a file so that your reports come in faster than any other website. File Format Input file
  • 9. The file is formatted as follows in which each line represents one game: The first token is an integer that can be either 1 or 0 . It is 1 if the first team won and it is 0 if the second team won . This token is followed by exactly five tokens representing the player names of the first team (separated by spaces). After that, the token vs token follows and finally five tokens for the player names of the second team. For example, this line means the second team with players Prelich Murphy Wilkes Gall Greenberg has won : 0 Chan Stine Neilson Curtis Kennedy vs Prelich Murphy Wilkes Gall Greenberg Your Task Implement a class Stats with a static class method wins that reads lines of input from a BufferedReader and computes winner statistics for each of the players mentioned in the input, by constructing a
  • 10. HashMap mapping the names of the players ( String ) to the number of wins ( Integer ) that player has accumulated, and returns the resulting HashMap . Now, implement a static class method winner that iterates through a HashMap , such as returned by wins , returning the name of the player with the most wins (in the case of a tie, return any such player). Make sure to test your methods.