0

I have been sitting on this for about 2 days now. My assignment is to create a leftist max d-heap in java. I am provided with the outline as follows:

public LeftistDHeap(int d)
public void enqueue(T element)
public T dequeue()
public String breadthFirstSearch()
public String depthFirstPreOrder()
public String depthFirstPostOrder()
public void combine(LeftistDHeap<T> other)
public boolean isEmpty()

So I have done all the functions they ask for here (only not depthFirstPostOrder()). My Node class is like a normal treeNode class, only instead of left and right, I have an array of pointers to the children.

I just cant figure out the logic on how to do a post-order traversal in this tree. I binary post search is easy, so is there a way to convert the normal binary tree post-order algorithm to work with a tree with d-amount of children?

Elterado
  • 5
  • 3

1 Answers1

0

I can already tell you that you will have a problem with using arrays and generic types. I suggest that you use a different data structure to store you children. Maybe a linked list? I say that because I too have the same assignment for COS212, Fitchfork will complain about your use of arrays. As for the post-order traversal, I too am lost, hence coming upon your question.

I used this website to help me with the post-order traversal: http://leetcode.com/2010/10/binary-tree-post-order-traversal.html it has a lot of good examples on how to do it differently. Good luck!

dillib
  • 359
  • 1
  • 2
  • 11
  • Thanx for that. The website is very help full, however, I am not sure why you say that Fitchfork would have a problem with the use of an array as my data structure? The problem with a linked list is that it would take a lot of time to find one specific child at some index. I am now looking at adding a helper function to do it recursively, as the iterative version seems to be very complex when there are more than 2 children. – Elterado Mar 05 '15 at 06:01