java - How can I add functions to a priority queue? (Is it even possible) -
i know priority queue , know how add together strings/integers it. want add together functions it. (if makes sense??) . not ready alter homecoming type of function.
i want know how can go doing that? made raw type priority queue
priorityqueue prq = new priorityqueue (); prg.offer(login());
now, not coding genius, learning. wanted see if possible. if isn't possible there alternate solutions?
my pop() function run function got pop'd. of functions void.
an thought got: should insert string , switch statement depending on string pop()???
what doing putting return value of function in queue. function executes , value produces set queue. instead have queue of runnable
s , phone call run()
method on them:
priorityqueue<runnable> queue = new priorityqueue<runnable>(); queue.offer( new runnable() { public void run() { login(); } ); queue.remove().run();
or, if using java 8:
priorityqueue<runnable> queue = new priorityqueue<>(); queue.offer(() -> login(););
java priority-queue
No comments:
Post a Comment