Youll see how more complex it seems and so insert is

Info icon This 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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern