How to implement heap as a binary tree in lisp?



I am trying to implement heap in CLisp. I have already done it in a
linear data strcuture with no left / right pointers. But now I want to
use a nested list format which contains (el () ()) at the highst
level.
The problem I am facing with is how to define a recursive case for
insertion. Heap requires the tree to be complete.

I approach the issue as follows:

1. I will take a heap and an element
2. I will add the element in the last node keeping it a complete tree
3. I wil swap the child with parent if it is greater than the parent

But I am stuck at the second step i.e. how to add an element without
making the tree incomplete? KIndly help me on this!!!!!!!

.



Relevant Pages

  • [SUMMARY] Drawing Trees (#40)
    ... Did you spot the errors in my Heap class? ... It may be interesting to note that this quiz grew out of an actual problem I was ... then initializes a String to hold the result and a root node for the tree. ...
    (comp.lang.ruby)
  • Re: iterative binary tree traversal
    ... >> A stack isn't strictly necessary, ... >> into a heap; the heap lets you backtrack to scan down branches you ... pointer to a node in the tree. ... // iterate repeatedly over heap until we have no more entries to add ...
    (comp.programming)
  • Re: How to implement heap as a binary tree in lisp?
    ... Heap requires the tree to be complete. ... I wil swap the child with parent if it is greater than the parent ... Keep a weight slot in each node. ...
    (comp.lang.lisp)
  • [QUIZ] Drawing Trees (#40)
    ... The three rules of Ruby Quiz: ... Array), you can use easy math to find child nodes. ... because you don't usually access a Heap by index. ... However, we generally envision a Heap as a tree, ...
    (comp.lang.ruby)
  • Re: Priority Queue confusion
    ... Reading Algorithms in C by Robert Sedgewick tells me that a PQ is not a dad structure but actually an ADT which is implemented using a Heap. ... Heap itself is implemented using a Tree. ... If it's a binary tree, then there should be plenty of tutorials available. ... find first member x such that lessThan(x, newElement) * ...
    (comp.programming)