Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

-------------- Link download http://www.mediafire.com/file/csicrkcc7y63bto/Queue

ID: 3799083 • Letter: #

Question

--------------

Link download http://www.mediafire.com/file/csicrkcc7y63bto/QueueP.cp

2. (10 points) An operation that displays the contents of a queue can be useful during program debugging. We will use the pointer-based implementation of the queue from lecture: (Download below) Write two different versions of display as member functions of the queue class such that: a. display 1 uses only ADT queue operations, so it is independent of the queue's implementation. Use the queue interface from class. b. display 2 assumes and uses the pointer-based implementation of the ADT queue. Both operations should leave the queue in the same state as when it started.

Explanation / Answer

a) We are making an assumption that the queue implements some method say get(i)
that gets the elements from the queue.

void display(){
if(queue.head==NULL){ //If queue's head == null, then it is empty. Then printout empy queue'
cout <<"Queue empty";
}
else{ //else get each element of queue using get() method
while (queue.get(i) !=NULL){
cout<<queue.get(i);
}
}
}

b) As per the question the display 2 uses pointer based implementation of the ADT. So we iterate by accessing the pointer unill we get a Null.

void display(){
node *temp;
temp=head;
if (temp == NULL){
cout <<"Queue empty";
}

else{
while(temp != NULL){
cout <<temp->data<< " ";
temp=temp->next;
}
}
}