-2

I have to implement a data structure for a IT ticket system which is ordered by priority. So i am going to implement a priority queue. I have both a linkedlist class(and a node class for this) and a min-heap class but not sure which i want to use yet. I also have a main class which basically tests that the data structure works. I then have a request class which holds information about a request:

  • String creatorName;
  • String problemDescription;
  • String ownerName;
  • int uniqueID;
  • int priorityNo;

What im stuck on is how i link the data in the request class to the data structure class so that it can store it and perform the methods correctly. Any help would be greatly appreciated.

RHH
  • 27
  • 6
  • your data structure class should contain an `add()` or `insert()` method or something similar to add a new object to. For example, an `ArrayList arr` in Java has an `add()` to add new Strings to the list ( `arr.add("hello")` ) – user3170251 Nov 07 '18 at 21:31
  • You can check implementation of collections included into JDK like `ArrayList`, `LinkedList`, `PriorityQueue` – Ivan Nov 07 '18 at 21:33
  • the task set out is that i cannot use any collections so i have created my own min-heap and linkedlist but now need to be able to understand how to link the requests to whicever datastructure i pick – RHH Nov 07 '18 at 21:35
  • What's the difference between you checking source code of collection yourself and reading the very same code as answer for your question on SO provided by another person? – Ivan Nov 07 '18 at 22:14

1 Answers1

0

Use the LinkList structure with insertion sort, keep the highest priority at the head or tail, that way each insert will cost you O(n) while finding the min will always cost you O(1), you need to implement comapreTo for each node and you can use it for the sorting.

if you have two classes you can use the request as a decorator for the ticket itself. that way the request will "hold" the ticket.