Skip to content

Commit

Permalink
delete a tree
Browse files Browse the repository at this point in the history
  • Loading branch information
NripeshKumar committed Oct 11, 2019
1 parent 87f26a3 commit bc30d55
Showing 1 changed file with 1 addition and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
#include<bits/stdc++.h>
#include<iostream>
using namespace std;

/* A binary tree node has data,
pointer to left child and
a pointer to right child */

class node
{
public:
int data;
node* left;
node* right;

/* Constructor that allocates
a new node with the given data
and NULL left and right pointers. */
node(int data)
{
this->data = data;
Expand All @@ -24,24 +17,17 @@ class node
};


/* This function traverses tree
in post order to delete each
and every node of the tree */
void deleteTree(node* node)
{
if (node == NULL) return;

/* first delete both subtrees */
deleteTree(node->left);
deleteTree(node->right);

/* then delete the node */
cout << "\n Deleting node: " << node->data;
free(node);
}


/* Driver code*/
int main()
{
node *root = new node(1);
Expand All @@ -58,4 +44,3 @@ int main()
return 0;
}

//This code is contributed b

0 comments on commit bc30d55

Please sign in to comment.