Describe Trees using C++ with an example.



Describe Trees using C++ with an example...

Answer / 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

More C++ General Interview Questions

Explain one method to process an entire string as one unit?

1 Answers  


Will c++ be replaced?

1 Answers  


Explain rtti.

1 Answers  


Have you used MSVC? What do you think of it?

2 Answers   Google,


Explain the concept of copy constructor?

1 Answers  


Brief explaination about #include<iostream.h>, cin and cout

3 Answers  


What is difference between rand () and srand ()?

1 Answers  


Explain differences between alloc() and free()?

1 Answers  


Can there be at least some solution to determine the number of arguments passed to a variable argument list function?

1 Answers  


Which is best c++ or java?

1 Answers  


What are Virtual Functions? How to implement virtual functions in "C" ?

3 Answers  


Are there interfaces in c++?

1 Answers  


Categories