Discussion:
A2 Q1
(too old to reply)
kun qian
2011-10-10 06:43:42 UTC
Permalink
For the HeapInsert Algorithms shown on the slides I believe in the
while loop there should be an assertion that j >0. Since if i is 1
then j will be 0, which gives undefined behavior when exchanging.
Please correct me if I am wrong.

Thanks.
cs240
2011-10-10 17:19:47 UTC
Permalink
If i is 1, the while loop won't be executed anyway.

Vivian
CS240 Tutor
Post by kun qian
For the HeapInsert Algorithms shown on the slides I believe in the
while loop there should be an assertion that j >0. Since if i is 1
then j will be 0, which gives undefined behavior when exchanging.
Please correct me if I am wrong.
Thanks.
kun qian
2011-10-10 19:03:01 UTC
Permalink
Post by cs240
If i is 1, the while loop won't be executed anyway.
Vivian
CS240 Tutor
Post by kun qian
For the HeapInsert Algorithms shown on the slides I believe in the
while loop there should be an assertion that j >0. Since if i is 1
then j will be 0, which gives undefined behavior when exchanging.
Please correct me if I am wrong.
Thanks.
You are correct, I made a typo when trying the code. i should be
greater than 1.

Loading...