title: What is an efficient way to read/write a priority queue to a text file?
body: <p>I have a priority queue class that I implemented in Java as it being an array of queues. I need a good way (without using Serialization) of recording and storing the contents of the priority queue after each "transaction" or enqueue()/dequeue() of an object from the priority queue. It should serve as a backup in the event that the priority queue needs to be rebuilt by the program from the text file.</p>
  
  <p>Some ideas I had and my problems with each:</p>
  
  <ul>
  <li><p>After each "transaction", loop through the queues and write each one to a line in the file using delimiters between objects.
  -- My problem with this is that it would require dequeueing and re-enqueueing all the objects and this seems highly inefficient.</p></li>
  <li><p>After each enqueue or dequeue simply write that object or remove that object from the file.
  -- My problem with this is: if this is the approach I should be taking, I am having a hard time coming up with a way to easily find and delete the object after being dequeued.</p></li>
  </ul>
  
  <p>Any hints/tips/suggestions would be greatly appreciated!</p>