in GATE retagged by
1,143 views
2 votes
2 votes

Fill in the blanks in the procedure:

void
Prod (Element Type X, Priority Queue H)
{
int i;
if (IsFull(H))
{
Error ("Priority queue is full");
return;
}
for (i=++H -> size; H -> Elements [i/2]>X; i/=2)
_________________
}


Find the statement which has to be placed below the for loop for inserting a key.

  1. $H$$\rightarrow$ Elements $[i]=H$ $\rightarrow$ Elements [i/2];       $H$ $\rightarrow$Elements $[i] = X$;
  2. $H$$\rightarrow$ Elements $[i/2]=H$$\rightarrow$ Elements $[i/2]$;
  3. $H$$\rightarrow$ Elements $[i^2 ]=X;$
  4. $H$$\rightarrow$ Elements $[i]=X;$
in GATE retagged by
by
1.1k views

4 Comments

Okay, so in C, postfix "++" has higher precedence than "-->", but prefix "++" has lower precedence than "-->" (Source).

So, the condition in the for loop

for (i=++H --> size;

will be evaluated as

for (i= ++(H-->size);

and not throw a compiler error as I thought it would.

0
0

The for loop does not have curly braces so only 1st statement is executed inside for loop and second statement is executed after entire for loop. Such a subtle detail… Nice question!

0
0

@Harsh181996

your comment made it clear :)

thank you 

0
0

1 Answer

0 votes
0 votes
Best answer
This is a pseudo-code to insert a Node in a Priority queue.

The above code for insertion of node in min heap .

Option A is correct .
selected by
Answer:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

64.3k questions

77.9k answers

244k comments

80.0k users