Question
Asked by:
ryan36870
ryan36870
Rating : No Rating
Questions Asked: 2
Tutorials Posted: 0
 

$25.00 Binary Search Tree in C++

Q:
Consider the problem of organizing a collection of user-id's and passwords. Each time a user logs in to the system by entering his or her user-id and a secret password, the system must check their validity. Because this validation must be done many times each day, it is necessary to structure this information in such a way that it can be searched rapidly. Moreover, this must be a dynamic structure because new users are regularly added to the system. BST's can searched rapidly and it is a dynamic structure. Thus, the major operations needed are provided in the BST class.

* Build a BST of UserInfo objects. (Is there an STL that will assist programmers who are constructing BST's?)
* Search the BST for a given UserInfo object entered from the keyboard.
* Display a meassage indicating if the user is a valid user or not.

The class UserInfo will have the user-id and password (both strings) as data members. Since searching and inserting into a BST requires being able to compare values stored in it with < and ==, we must overload these operators for UserInfo. And we also need an input operation, so we will overload >> for it.
 


   
   
   
   
 
Available Tutorials to this Question
Posted by:
rainman
rainman
Rating (40): A+
Questions Asked: 2
Tutorials Posted: 174, earned $906.64
 

$30.00 C++ Binary Search Tree For UserInfo Validation. Lots of Comments. Compiles, Tested, Works

  • This tutorial was purchased 5 times and rated A+ by students like you.
  • Posted on Feb 26, 2009 at 5:58:04PM
A:
Preview: ... i);<br>}<br><br>void BinaryTree::insert(Node*& n, UserInfo i)<br>{<br> //Inserts the user info based on its value discussed in the UserInfo class.<br> //If the value is less than the current node's (n) it inserts it into the left node<br> //if the value is greater than (or equal to) node n then it inserts it to the right<br> //if the node is null then it creates a new node with the user information.<br> if (n)<br> {<br> if (i < n->info)<br> insert(n->left, i);<br> else<br> insert(n->right, i);<br><br> }<br> else<br> {<br> n = new Node(i);<br> }<br>}<br><br>bool BinaryTree::validate(string name, string pass)<br>{<br> //Creats a userinfo object to find the name in the binary tree<br> //starting at the root.<br> UserInfo info;<br> info.setName(name);<br> info.setPass(pass);<br> return validate(root, info);<br>}<br><br>bool BinaryTree::validate(Node* n, UserInfo info)<br>{<br> //If the node is null then there is no number there<br> if (n == NULL)<br> {<br> cout << info.getName() << " was not found." << endl;<br> return false;<br> }<br><br> //if the search value is less than this node's value, then it might<br> //be stored in the left node.<br> if (n->info > info)<br> return validate(n->left, info);<br><br> //if the search value and node values are equal then it might be stored in this node<br> if (n->info == info)<br> {<br> //If the names are the same then we found it ...

The full tutorial is about 1689 words long plus attachments and additional clarification.

Attachments:
bstree.cpp (7K) (Preview)
preview.JPG (48K) (Preview)
   
Join Now or Log In
Get Tutoring
Get Paid
Academic Honesty