PA07-L9 -- Binary Search Tree ADT


Items for this week

  • Implementation Testing
  • Programming Exercise 1 - database
  • Programming Exercise 2 - getCount, getHeight
  • Analysis Exercise 1 and 2

Notes: Delete Node

  • As we talked in class, deleting a node has a few easy cases and 1 hard case.
    • Easy Case 1: the node to delete has no children - then delete it.
    • Easy Case 2: the node to delete has only 1 child - delete the node like you would in a linked list.
    • Hard Case: the node to delete has 2 children. This is where it is a little tricky.... you whant to keep the tree in order so you find the node that is directly before it in sorted order, delete it from the tree and place it's data into the original node. So, how do you find that node? Go left one link and then go right as far as you can.... that is the node...

Notes: Programming Exercise 1

Sample lines of code you will want to know...

    // Output the account IDs in ascending order.
    cout << endl << "Account IDs :" << endl;
    index.writeKeys();
    cout << endl;
    
    cout << "Enter account ID : ";
    cin >> searchID;
    
    
    cout << recNum
         << " : " << acctRec.acctID
         << " " << acctRec.firstName
         << " " << acctRec.lastName
         << " " << acctRec.balance;