adspace


Describe Trees using C++ with an example.

Answer Posted / Ramesh Chandra

In C++, a tree can be implemented as a class hierarchy. Here's an example of a simple binary tree implementation:

```cpp
class Node {
public:
int data;
Node* left;
Node* right;

// Constructor to initialize the node with given data and NULL pointers for children
Node(int value) : data(value), left(nullptr), right(nullptr) {}
};
```

Then, you can create and manage the tree by using functions like `insert`, `find`, `deleteNode`, etc. This simple binary tree can be extended to implement more complex trees like AVL, BST, B+ tree, or threaded binary tree.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

daily Routine of father

1485


What is the latest version on c++?

1209


How c functions prevents rework and therefore saves the programers time as wel as length of the code ?

1165


What character terminates all character array strings a) b) . c) END

1397


Can union be self referenced?

1267