How to pop from a queue that just supports enqueue/dequeue:
You can extract any arbitrary member of a queue,eg nth member, by cycling the queue, ie dequeing and immediately re-enqueing n-1 members, then the next dequeue is the desired member. (If that wasn't the last member then you also need to keep dequeing/re-enquening until all the members have been processed so as to leave the queue in its original order.)
You can use a similar cyclic rotation of the queue to insert new members at the head of the queue instead of the tail, if you prefer.
Oh wow, if you can't query the size of the queue that makes it harder.
Maybe you could keep your own counter of the number of elements in the queue?
Alternatively you could use the second approach (add new items at the front of the queue by adding it at the end and cycling the queue until it reaches the front). In that maybe case you could use a sentinal value, so you would know when you have reached the front while cycling the queue. Something like:
enqueue sentinal value
dequeue entries and re-enque them until you find the sentinel value
// item is now the first entry in the queue
I am writing a java program that needs to execute shell commands, so I wrote a function that would take the command to execute as a string (ie: "mkdir ~/Folder1") and execute that command with the shell. Here is the function:
Runtime run = Runtime.getRuntime();
Process pr = ...
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.