nus-cs2030 / 2122-s2

CS2030 repository and wiki for AY 2021/2022 Sem 2
MIT License
0 stars 0 forks source link

Did anyone use PQ to store Servers? #573

Open denshem10 opened 2 years ago

denshem10 commented 2 years ago

Summary

In my solution, I used a PriorityQueue to store Servers and used different Comparators to sort the Servers based on priorities. My Server has 3 main attributes, int serverID, int serveStatus and int waitStatus. I sorted the Servers based on whether they can be served, then whether they can be waited. If one server had the same serveStatus and waitStatus as another server, the serveID was used to break the tie.

Description

Comparator<Server> comparator = new ServerComparatorService().thenComparing(new ServerComparatorWait() .thenComparing(new ServerComparatorName());

Did anyone else do this? Please share!

bryankwe commented 2 years ago

That's quite interesting. So you poll() each Server out during the Arrive event and add() that Server back once Done?

I think most of us did it using ImList<Server>. For me, I had some methods in Shop to help with the assignment of Servers in Arrive event

kh1js commented 2 years ago

I think using a PriorityQueue works but a ImList would be more flexible

jlee1007 commented 2 years ago

ImList seems to work better?

coffeecode2 commented 2 years ago

I think both method works, however, like the rest have mentioned, ImList would be more convenient. There also not really a need to create a comparator specially for the servers just for them to be placed in a PQ.

Zhenyubbx commented 2 years ago

yeap ImList will work better because there's no need to have any specified order of the servers

aldrichwilliams23 commented 2 years ago

Hi! Personally, I use ImList for the server, I think using PQ might be possible, but I believe it might create additional complication, use the simpler method instead if it works well!

Swagston20 commented 2 years ago

Used ImList cause PQ need to create new Comparator so more troublesome