Sei sulla pagina 1di 4

Algorithm : insert_heap(item)

1.
2.
3.
4.

n=n+1
//Add a new node to H
ptr=n-1
// initialise ptr to the new node added
TREE[ptr]=item
// find parent of the new node
while(ptr>0)
1. parent =(ptr-1)/2
2. if(TREE[ptr]>TREE [parent])
1. Swap( TREE[ptr] and TREE[parrent] )
// exchange
2. ptr=parent
// current position of the
inserted node

3. Else
1. Break // no need to exchange,
4. Endif
5. endwhile
6. stop

Algorithm : Delete _heap

Potrebbero piacerti anche