Welcome! Log In Create A New Profile

Advanced

queues in data structures

Posted by annitaz 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
queues in data structures
May 26, 2011 10:26AM
template < class Object>
void fix(queueType < Object> &q, int n)
{

if (n>=1)
{

Object temp = q.front();
q.deleteQueue();
fix(q,n-1);
q.addQueue(temp);
}

}

(a)what will the final state of queue q1 be after the statement fix(q1,2); is exexuted, if q1 has the values (1,2,3,4,5}

my answer: {2,3,4,5,1} because q.addQueue adds an element at the back
step 1: if (2>1) true
step 2: element {1} added to temp
step 3: q.deleteQueue(); deletes element{1}
step 4: fix(q1, 2-1)
step 5: q.addQueue(temp); element{1} is added at the back of the queue

b) what does function fix() do?

It restores the deleted element at the end of the queue

c) A precondition for fix() is: The queue exists and it is not empty
avatar Re: queues in data structures
May 26, 2011 05:42PM
Your answer for b) describes the mechanism, not the function.

The correct answer is that fix() moves the front n - 1 elements of the queue to the back of the queue.
Re: queues in data structures
May 26, 2011 11:11PM
(a)what will the final state of queue q1 be after the statement fix(q1,2); is exexuted, if q1 has the values (1,2,3,4,5}
Sorry, only registered users may post in this forum.

Click here to login