write iterative function 5. Priority Queue (4 points) Suppose we define a priori
ID: 3855916 • Letter: W
Question
write iterative function
Explanation / Answer
Here is the code for the function:
node* find(pq queue, int val)
{
node* ptr //pointer to traverse the circular linked list
int flag=0; //to keep check if the desired element was found or not
ptr=pq.pRear; //assigning the first element to our pointer variable
if(ptr->info==val)
flag=1; //element found at the first check itself
else
{
ptr=ptr->pNext; /*now start traversing the list if first element is not desired element, till you find the element or the list ends, that is ptr again becomes equal to pRear*/
while(ptr!=pq->pRear)
{
if(ptr->info==val)
{
flag=1; //element found
break; //now end loop
}
else
ptr=ptr->pNext; //go to next element
}
}
if(flag==1)
return ptr; //the element pointer
else
return NULL;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.