GeeksforGeeks » Interview Questions
Space efficient data structure for n queues
(3 posts)-
Give a good data structure for having n queues (n not fixed) in a finite memory segment. You can have some data-structure separate for each queue. Try to use at least 90% of the memory space.
-
struct {lastPosition, data}
Queue1, Queue2.. QueueN...
where the queue class has DequeuePtr, Enqueue() and Dequeue() as defined below.DequeuePtr : Keeps track of the Dequeue postion from the finite memory for
Enqueue(): finds the next available position from the finite memory, creates a new struct instance, adds the data to it and fill the last position as null, if its the first element. Add the new position to struct dequeue ptr.
If its not the first elemet, find the next available postion, create a struct, add the data to it, fill the last postion using the struct deque ptr value. update the dequeue ptr to the position of this struct.Dequeue() : use the queue's dequeue pointer to read the struct, print the data, set the deque pointer to the lastpoistion reterieved from the struct.
use the individual instances to Enqueue/Dequeue data..
-
struct {lastPosition, data}
Queue1, Queue2.. QueueN...
where the queue class has DequeuePtr, Enqueue() and Dequeue() as defined below.DequeuePtr : Keeps track of the Dequeue postion from the finite memory for
Enqueue(): finds the next available position from the finite memory, creates a new struct instance, adds the data to it and fill the last position as null, if its the first element.
Add the new position tostructdequeue ptr.If its not the first elemet, find the next available postion, create a struct, add the data to it, fill the last postion using the
structdeque ptr value. update the dequeue ptr to the position of this struct.Dequeue() : use the queue's dequeue pointer to read the struct, print the data, set the deque pointer to the lastpoistion reterieved from the struct.
use the individual instances to Enqueue/Dequeue data..
Reply
You must log in to post.