| | |
Problem with Trie..
Please support our Ruby advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2008
Posts: 5
Reputation:
Solved Threads: 0
So I'm writing a program that reads in a file which has each word on a different line. The program is supposed to loop through the file in such a way that when it reads a line and gets to the end of the line it adds that word to an array and inserts it into a trie that I have created then it does it for the second, third and so on. However, every time I insert a new word the existing trie is overwritten. How can I loop through so that my trie continues to hold on to the previously inserted words? And yes I know that my code is probably written horribly.
Ruby Syntax (Toggle Plain Text)
def hw2 puts "What file would you like to read?" name = gets.chomp puts "What file would you like to write to?" name2 = gets.chomp f1 = File.new(name2, "w+") aFile = File.open(name, "r") array = [] while char = aFile.getc char = char.each_byte { |ch| } array.push char first = array.first rest = array.reverse rest.pop rest = rest.reverse t2 = insert(first, rest) if char == "\n" array.clear end end print t2 print "\n" end
![]() |
Similar Threads
- VB: Connect to Access database via ODBC datasource name (Visual Basic 4 / 5 / 6)
- Infinite loop problem (C)
- Import Main problem (Python)
- phonebook problem (C++)
- Bearshare prob (Windows NT / 2000 / XP)
- dvd burning problem (IT Professionals' Lounge)
- Trie/Tree addWord() method (Computer Science)
- Web pages won't open (Viruses, Spyware and other Nasties)
- Missing Thumbnails (Web Browsers)
Other Threads in the Ruby Forum
- Previous Thread: dynamic menu using ruby
- Next Thread: Ruby - GUI - Desktop Programming - Tools required
| Thread Tools | Search this Thread |





