Problem with Trie..

Please support our Ruby advertiser: SELL YOUR PRODUCT TODAY !
Reply

Join Date: Feb 2008
Posts: 5
Reputation: vesper967 is an unknown quantity at this point 
Solved Threads: 0
vesper967 vesper967 is offline Offline
Newbie Poster

Problem with Trie..

 
0
  #1
Mar 25th, 2009
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.

  1. def hw2
  2. puts "What file would you like to read?"
  3. name = gets.chomp
  4. puts "What file would you like to write to?"
  5. name2 = gets.chomp
  6.  
  7. f1 = File.new(name2, "w+")
  8. aFile = File.open(name, "r")
  9. array = []
  10. while char = aFile.getc
  11. char = char.each_byte { |ch| }
  12. array.push char
  13. first = array.first
  14. rest = array.reverse
  15. rest.pop
  16. rest = rest.reverse
  17. t2 = insert(first, rest)
  18.  
  19. if char == "\n"
  20. array.clear
  21. end
  22. end
  23.  
  24. print t2
  25. print "\n"
  26. end
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Ruby Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC