Youll see how more complex it seems and so insert is

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: rt Here's readability again. Do you understand the recursive version more easily? We start with a recursive function to insert a new node. Let's now try insertion. 6 void InsertNode(void* data, nodePtr& root) { if (root == NULL) { root = new node; rootroot->data = data; rootroot->left = 0; root->right = 0; } else if (ListDataCmp(data,root->data)<=0) (ListDataCmp(data,rootInsertNode(data,rootInsertNode(data,root->left); else InsertNode(data,rootInsertNode(data,root->right); } Before we talk about deletion, let's consider how we can utilise the tree and its order characteristics. We would like to work our way through the data in the order specified by the comparison function in the order specified by the comparison function. When we put values in an array according to some comparison function, we were sorting. Consider this earlier binary tree. This is not a binary search tree. InsertNode(data, root); In the case of trees there are a number of ways of traversing the data. We visit nodes according to some rule. The way we want now is so that the...
View Full Document

This document was uploaded on 04/07/2014.

Ask a homework question - tutors are online