-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryTreeInterface.h
More file actions
45 lines (36 loc) · 1.55 KB
/
BinaryTreeInterface.h
File metadata and controls
45 lines (36 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Created by Frank M. Carrano and Tim Henry.
// Copyright (c) 2013 __Pearson Education__. All rights reserved.
/** Listing 15-1.
@file BinaryTreeInterface.h */
#ifndef _BINARY_TREE_INTERFACE
#define _BINARY_TREE_INTERFACE
template<class ItemType>
class BinaryTreeInterface
{
public:
/** Virtual destructor allows concrete implementations to clean up
heap memory when the BinaryTree is discarded. */
virtual ~BinaryTreeInterface() {}
/** Gets the data that is in the root of this binary tree.
@pre The binary tree is not empty.
@post The root’s data has been returned, and the binary tree is unchanged.
@return The data in the root of the binary tree. */
virtual ItemType getRootData() const = 0;
/** Traverses this binary tree in preorder (inorder, postorder) and
calls the function visit once for each node.
@param visit A client-defined function that performs an operation on
or with the data in each visited node. */
//precondition: the tree has not been traversed
//postcondition: the tree has been traversed
//returnType: void
virtual void preorderTraverse(void visit(ItemType&)) const = 0;
//precondition: the tree has not been traversed
//postcondition: the tree has been traversed
//returnType: void
virtual void inorderTraverse(void visit(ItemType&)) const = 0;
//precondition: the tree has not been traversed
//postcondition: the tree has been traversed
//returnType: void
virtual void postorderTraverse(void visit(ItemType&)) const = 0;
}; // end BinaryTreeInterface
#endif