indexing

Niko Schwarz niko.schwarz at gmx.net
Tue Jun 11 17:51:50 UTC 2002


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am Dienstag, 11. Juni 2002 19:16 schrieb Andreas Raab:

> So given your code
> snipped all you should have to do is to write:
>
> replace: v
> 	a at: 1 put: v.
> 	self downheap: 1.
> 	^ a at: 1.
>
> What's wrong with that?

It does not match the definition of replace.
Replace is to replace only if the elemnt is <= the top -- as defined in 
Sedgewick algorithms. 
(I sure can do it different -- but hello: why shouldnt it be possible like it 
is in every other language?)

> First of all, it checks if the heap is empty - and
> that's an operation which would be required no matter if you do
> zero-based indexing or not.

No. You didn't understand the original program. If you have a sentinel at top, 
and replace it with v, then downHeap: 0 will do the work. No additional check 
needed.

regards,

nick
- -- 
A novice was trying to fix a broken Lisp machine by turning the power
off and on.  Knight, seeing what the student was doing spoke sternly:
"You can not fix a machine by just power-cycling it with no
understanding of what is going wrong."  Knight turned the machine off
and on.  The machine worked.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9Bji2c9uyCiO8RNQRAkLMAJ97GK14zkioQmVZN/ut+z4qG90Q9QCffIy2
7HlWpIk7wSSNHlVzmeK3UBA=
=PPgG
-----END PGP SIGNATURE-----




More information about the Squeak-dev mailing list