Lec14BSTs

# Lec14BSTs - Potential use of a BST Count the number of...

This preview shows pages 1–2. Sign up to view the full content.

Potential use of a BST: Count the number of occurrences of each word in a file Print out the words in descending order of how often you saw them Two separate tasks: Count occurrences Print out in descending order of occurrences High-level solution: As you read in the file, parse it into words For each word, check if it is in the BST. If it is, increment occurrences. // note that we don't remove from the tree - we get from the tree // and change what is in the object. This is why we hold pointers! else, insert into the BST with a starting number of occurrences = 1 The BST is sorted by word Do this for the whole file. Then, go through and get each word out and place into another BST sorted by the number of occurrences. Then, you can print out from that BST from largest to smallest. Let's just work on the first task. Show the code for the midterm 1 problem counting words. What pieces of information do we need to hold? char *word int occurrences What methods do we need to implement? Constructor

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

Lec14BSTs - Potential use of a BST Count the number of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online