Thursday, 10 April 2014

Alternative Assignment

Write a program that contains a set of routines for manipulating a personal phone directory. The directory should be maintained as a binary search tree with each node containing a reference to an object containing fields for a family name, given name, address and telephone number. The tree’s node should be ordered using family names as keys. If there are entries with identical family names, given names should be as a secondary keys. No entries will have identical family and given names. 

The program should be menu driven with the user being offered a choice of 6 commands: 

  1. Insert
  2. Delete
  3. Edit
  4. Search
  5. Print
  6. Exit and give choice of print. 

I'm currently thinking about the logistics of programming it, and I think it can be in the console window - it shouldn't matter all that much. Here are the things that might be important: 

  • Inserting the Entry
    • Console Window asking 
  • Other List Class
    • First Name
    • Last Name
    • Address
    • Telephone
    • Left Child
    • Right Child
  • There are examples of inorder in the examples, so I can flip it around and do preorder. 
  • Family Names
    • This is how they are organized in the tree. 
    • If alphabetically, the thing goes before the given name, add it to the left. If not, add it to the right. 

Here's the criteria for the assignment:

Criteria
Application:
You include some form of planning. This is my planning, doesn't that work? Hehe. 
You use reusable classes and methods AND reuse them. Well, I'm going to be calling methods back and forth and be reusing the set and gets. 
You use dynamic data structures. Uh, yeah. Binary search tree..
You read from, and write to, files. Well, yeah...
You correctly make variables and methods private or public, including accessor (.get()) and mutator (.set()) methods. Done. 
Thinking & Inquiry:
You write a paragraph explaining how you used dynamic data structures in your program, and compare that with what limitations finite data structures would have. Oh...well I'll get on that ;) 
Your program runs correctly. Test for invalid or incorrect input. Oh. Uh. Well I'll handle that when I'm done? 
You write a paragraph describing the differences between a number of different dynamic data types and why you chose the one you did, and why you didn’t choose the others). PAH. I didn't end up choosing...but I guess I'll go with the flow. :P 
Dynamic Data Structures in My Program

I'm using binary search trees in my program. It's a phone directory that is sorted by one's given name (last name). In the notes, this would be known as the "key." If the user decides to start fresh (new directory), the first thing that they enter will be the root. Then, when they go to enter something else, the insert method (the recursive one) will go through the left or right subtree depending on whether it is before the root or after the given name of the root (if it is before, it goes to the left subtree; if it is after, it goes to the right subtree). If the user decides to use a preexisting directory that was printed using this program, it will read in all the information in preorder (root, left subtree, then right subtree). The create method (which I have yet to write) will end up creating a binary search tree using this information. The only problem with this is that we can't exactly "delete" notes from a tree, it's just a matter of setting a boolean in that node to be false, and so if it is set to false, the program won't save it (not printing it to the file). 

Differences Between Different Dynamic Data Structure Types and Why I Chose Binary Search Trees: 

I'm currently using binary search trees in my program because it said I had to use them for the assignment. But in reality, if given the choice, I would've have used linked lists. I understand linked lists much better because of the different nodes and whatnot, but I don't fully understand binary search trees because linked lists just make more sense in my head. I guess binary search trees have their pros and cons; pros being that it separates alphabetically the left and right subtree (anything alphabetically before the root is on the left subtree while anything alphabetically after is on the right subtree). But then there is a problem (or two) with binary search trees because you can't quite delete a node - you can have a boolean that determines whether it is deleted or not (false if not; true if it is) and then just not end up saving it (so it'll be pointing to null next time you open the directory). With linked lists, I think it would be much easier to delete an item (since I already have the method written for the mahjong program, and the 3-way switch makes a lot more sense in my head) versus just setting a boolean true or false. I could have used a stack, but it doesn't really apply to the phone book program because if I wanted to delete an entry given a certain name, I wouldn't be able to take it out otherwise the stack would "fall over" (imagining a stack of books here). But in reality, I can't actually delete it, and I can't exactly organize it alphabetically either. And it is the same with with queues, it wouldn't be helpful in this program because FIFO applies, and the phone book contacts don't want to be disappearing in the order that the user enters it. 

No comments:

Post a Comment