1 / 17

void write_method() /* Post: A short string identifying the abstract

Project 2 -- Analysis. void write_method() /* Post: A short string identifying the abstract data type used for the structure is written. */. Project 2 -- Analysis. void update(const String &word, Search_tree<Record> &structure, int &num_comps) /*

ace
Download Presentation

void write_method() /* Post: A short string identifying the abstract

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Project 2 -- Analysis void write_method() /* Post: A short string identifying the abstract data type used for the structure is written. */

  2. Project 2 -- Analysis void update(const String &word, Search_tree<Record> &structure, int &num_comps) /* Post: If word was not already present in structure, then word has been inserted into structure and its frequency count is 1. If word was already present in structure, then its frequency count has been increased by 1. The variable parameter num_comps is set to the number of comparisons of words done. */

  3. Project 2 -- Analysis void print(Search_tree<Record> &structure) /* Post: All words in structure are printed at the terminal in alphabetical order together with their frequency counts. */

  4. Project 2 – Analysis – Record.h class Record { public: Record(); // default constructor operator Key() const; // cast to Key Record (const Key &a_name); // conversion to Record void increment(); int frequency(); private: Key name; int count; };

  5. Project 2 -- Analysis – Key.h class Key { String key; public: static int comparisons; Key (String x = ""); String the_key() const; }; bool operator ==(const Key &x,const Key &y); bool operator >(const Key &x,const Key &y); bool operator <(const Key &x,const Key &y); bool operator >=(const Key &x,const Key &y); bool operator <=(const Key &x,const Key &y); bool operator !=(const Key &x,const Key &y);

  6. Project 2 – Analysis – Node.h enum Balance_factor { left_higher, equal_height, right_higher }; template <class Entry> struct Binary_node { // data members: Entry data; Binary_node<Entry> *left; Binary_node<Entry> *right; // constructors: Binary_node(); Binary_node(const Entry &x); // virtual methods: virtual void set_balance(Balance_factor b); virtual Balance_factor get_balance() const; };

  7. Project 2 – Analysis – Tree.h template <class Entry> class Binary_tree { public: // Add methods here. Binary_tree(); bool empty() const; void preorder(void (*visit)(Entry &)); void inorder(void (*visit)(Entry &)); void postorder(void (*visit)(Entry &)); int size() const; void clear(); int height() const; void insert(const Entry &);

  8. Project 2 – Analysis – Tree.h (cont) Binary_tree (const Binary_tree<Entry> &original); Binary_tree & operator =(const Binary_tree<Entry> &original); ~Binary_tree(); // tree testing commands Error_code remove(Entry &); void prenode(void (*f)(Binary_node<Entry> *&)); void swap(); void recursive_inorder(Binary_node<Entry> *, void (*visit)(Entry &)); void recursive_preorder(Binary_node<Entry> *, void (*visit)(Entry &)); void recursive_postorder(Binary_node<Entry> *, void (*visit)(Entry &)); void recursive_insert(Binary_node<Entry> *&sub_root, const Entry &x);

  9. Project 2 – Analysis – Tree.h (cont) int recursive_size(Binary_node<Entry> *sub_root) const; int recursive_height(Binary_node<Entry> *sub_root) const; void recursive_clear(Binary_node<Entry> *&sub_root); Binary_node<Entry> *recursive_copy(Binary_node<Entry> *sub_root); void recursive_swap(Binary_node<Entry> *sub_root); Binary_node<Entry> *&find_node(Binary_node<Entry> *&, const Entry &) const; Error_code remove_root(Binary_node<Entry> *&sub_root); protected: // Add auxiliary function prototypes here. Binary_node<Entry> *root; };

  10. Project 2 – Analysis – STree.h (cont) template <class Record> class Search_tree: public Binary_tree<Record> { public: Error_code insert(const Record &new_data); Error_code remove(const Record &old_data); Error_code tree_search(Record &target) const; Error_code search_and_insert(Binary_node<Record> *&, const Record &); Binary_node<Record> *search_for_node(Binary_node<Record>*, const Record&) const; Error_code search_and_destroy(Binary_node<Record> *&, const Record &); private: // Add auxiliary function prototypes here. };

  11. Project 2 – Analysis – String.h class String { public: // methods of the string ADT String(); ~String(); String (const String &copy); // copy constructor String (const char * copy); // conversion from C-string String (List<char> &copy); // conversion from List void operator =(const String &copy); const char *c_str() const; // conversion to C-style string protected: char *entries; int length; };

  12. Project 2 – Analysis – String.h (cont) bool operator ==(const String &first, const String &second); bool operator >(const String &first, const String &second); bool operator <(const String &first, const String &second); bool operator >=(const String &first, const String &second); bool operator <=(const String &first, const String &second); bool operator !=(const String &first, const String &second);

  13. Project 2 – Analysis – List.h template <class Node_entry> struct Node { // data members Node_entry entry; Node<Node_entry> *next; // constructors Node(); Node(Node_entry, Node<Node_entry> *link = NULL); };

  14. Project 2 – Analysis – List.h (cont) template <class List_entry> class List { public: // Specifications for the methods of the list ADT go here. List(); int size() const; bool full() const; bool empty() const; void clear(); void traverse(void (*visit)(List_entry &)); Error_code retrieve(int position, List_entry &x) const; Error_code replace(int position, const List_entry &x); Error_code remove(int position, List_entry &x); Error_code insert(int position, const List_entry &x);

  15. Project 2 – Analysis – List.h (cont) // The following methods replace compiler-generated defaults. ~List(); List(const List<List_entry> &copy); void operator =(const List<List_entry> &copy); protected: // Data members for the linked list implementation now follow. int count; Node<List_entry> *head; // The following auxiliary function is used to locate list positions Node<List_entry> *set_position(int position) const; };

  16. Project 2 – Analysis – Timer.h (cont) #include <time.h> class Timer{ public: Timer(); double elapsed_time(); void reset(); private: clock_t start_time; };

  17. Project 2 – Analysis – Timer.cpp Timer::Timer() { start_time = clock(); } double Timer::elapsed_time() { clock_t end_time = clock(); return ((double) (end_time - start_time)) / ((double) CLK_TCK); } void Timer::reset() { start_time = clock(); }

More Related