arrays - Pseudo-code for dequeue -


a queue held in linear array called q number of elements = limit (numbered 0 limit-1). oldest element of queue held in array element 0 (at front), next in array element 1, , on. variable stores index of array element containing newest element in queue (or -1 empty queue).

how write 'size' operation (in pseudo-code)?

**

you decrement index contains last element, , return value. next time add overwrite actual value of last element. pseudocode pretty simple then:

dequeue() {      returnvalue = queue[index];      queue.index = queue.index - 1;      return returnvalue;   } 

ie. algorithm inefficent. remove operation can done in constant time (fast) opposed being linear respect number of elements (slower).


Comments

Popular posts from this blog

android - Inheriting from Theme.AppCompat* -

broadcastreceiver - android BOOT_COMPLETED not received if not activity intent-filter -

basic authentication with http post params android -