Example #1
0
func buildTree(tc *tree.TreeCollection) {
	file, err := os.Open(fName)
	if err != nil {
		panic("File not found")
	}
	s := bufio.NewScanner(file)
	for s.Scan() {
		word := s.Text()
		tc.AddWord(word)
	}
	defer file.Close()
	if err := s.Err(); err != nil {
		panic("Error scanning file")
	}
}
Example #2
0
func longCompWord(tc *tree.TreeCollection) string {
	maxLength := 0
	longWord := ""
	file, err := os.Open(fName)
	defer file.Close()
	if err != nil {
		panic("File not found")
	}
	s := bufio.NewScanner(file)
	for s.Scan() {
		word := s.Text()
		if tc.IsCompound(word) && maxLength < len(word) {
			longWord = word
			maxLength = len(word)
		}
	}
	if err := s.Err(); err != nil {
		panic("Error scanning file")
	}
	return longWord
}