-1

First, I am a beginner. My teacher gave me a homework and told me exactly this:

"Your program will accept 1 file as input.
Each line consists of 1 string(name).
Your program will load all the names into a Heap data structure.
Then you will load the same file into a Set data structure.
Then you will load the same file into a LinkedList datastructure.
Print how long each loading takes."

From this, I understand that I need to load a .txt file into a heap data which has a few string(name) at a line. But I cannot find anything about loading a string type txt file into a heap data.

Which kind of heap data structure should I use? and how can I load that file into that heap data? Can you guys give me some recommendation please... Or am I misunderstanding the homework?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • you can use PriorityQueue for heap. To load data you can check https://stackoverflow.com/a/5868528/5313017 – Saim Doruklu Jun 10 '19 at 17:22
  • The PriorityQueue is implemented using a binary heap. Edit: You probably want to read the file line by line, then push it onto the heap. Good luck. – EDToaster Jun 10 '19 at 17:26
  • Let me google that for you: https://www.startpage.com/do/dsearch?query=java+load+text+file+into+set&cat=web&pl=opensearch&language=english https://www.startpage.com/do/dsearch?query=java+load+text+file+into+linked+list&cat=web&pl=opensearch&language=english – Robert Jun 11 '19 at 03:07

1 Answers1

0

Use Stack<T>. This is a one-to-one representation of what you need (at least I assume so because there is no class named Heap<T>) Use .push and .pop methods to add and remove items from the stack and just add the strings on a line-by-line basis.

J. Lengel
  • 570
  • 3
  • 16