#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <stdlib.h>
#include <vector>
#include "wl.h"
|
| int | buildTree (ifstream &srcfile, RBTree *tree) |
| | Build tree from the file handler and close it. More...
|
| |
| int | locate (RBTree *tree, string word, int index) |
| | Given the word and index, return the position in the file. More...
|
| |
| void | insert (RBTree *tree, string word, int pos) |
| | Insert the word and pos into the tree. More...
|
| |
| int | filterStr (string &line) |
| | Helper function that filter out all invalid characters. More...
|
| |
| int | splitstr (string &line, vector< string > &argvs) |
| | Split the command read from user input. More...
|
| |
| void | usage () |
| | Print out the usage. More...
|
| |
| void | invalidcmd () |
| | Print out the standard error message. More...
|
| |
| int | main (int argc, char *argv[]) |
| |
- Author
- Haiyun Jin
- Version
- 0.1
Description: Word locator Student Name: Haiyun Jin UW Campus ID: 9069998087 email: hjin3.nosp@m.8@wi.nosp@m.sc.ed.nosp@m.u
| int buildTree |
( |
ifstream & |
srcfile, |
|
|
RBTree * |
tree |
|
) |
| |
Build tree from the file handler and close it.
- Parameters
-
| srcfile | - ifstream file to read words from |
| tree | - pointer to the RBTree |
- Returns
- 1 if build successfully, -1 if failed
| int filterStr |
( |
string & |
line | ) |
|
Helper function that filter out all invalid characters.
- Parameters
-
| line | - The line to be filtered; |
- Returns
- -1 if no invalid char. 1 if at least one invalid char
| void insert |
( |
RBTree * |
tree, |
|
|
string |
word, |
|
|
int |
pos |
|
) |
| |
Insert the word and pos into the tree.
- Parameters
-
| tree | - tree pointer |
| word | - string word |
| pos | - int position |
Print out the standard error message.
| int locate |
( |
RBTree * |
tree, |
|
|
string |
word, |
|
|
int |
index |
|
) |
| |
Given the word and index, return the position in the file.
- Parameters
-
| tree | - The RBTree to look into |
| word | - A string of word to locate |
| index | - The index'th occurrence of word |
- Returns
- An integer of the postion in the file. If not found, return -1.
| int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
| int splitstr |
( |
string & |
line, |
|
|
vector< string > & |
argvs |
|
) |
| |
Split the command read from user input.
- Parameters
-
| command | - A string contains the command read |
| argvs | - arguements splited from the command |
- Returns
- -1 if cannot split. 1 if split successfully