Lec14BSTInClass

Lec14BSTInClass - Count the number of occurrences of each...

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

View Full Document Right Arrow Icon
Count the number of occurrences of each word in a file Print out those words in descending order of how often you saw them High-level solution: Read in each word of a file How I would do it on paper: Write down a word and then count how many times I see it 1) Look for the word on the paper 2) If I find it, put another hash mark If I don’t find it, write it down and put 1 hash mark next to it Write down “The”, put 1 hash mark next to it. “turkey” write it down, put 1 hash mark next to it. “The” 1) Look for the word on the BST 2) If I find it, put another hash mark If I don’t find it, insert into BST and put 1 hash mark next to it - word - counter variable – how many times we’ve seen it We will define a class that has a word and a counter Word.h: #ifndef WORD_H #define WORD_H using namespace std; class Word { char *word; int counter; public: Word(char *w){word = w; counter = 1;} char *getWord(){return word;} int getCounter(){return counter;} void incrementCounter(){counter++;}
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/27/2011 for the course CMPSC 24 taught by Professor Agrawal during the Fall '09 term at UCSB.

Page1 / 2

Lec14BSTInClass - Count the number of occurrences of each...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online