#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

struct node {
    int data;
    struct node* left;
    struct node* right;
};


struct node* simpul(int data) {
  struct node* node = (struct node*)
  malloc(sizeof(struct node));
  node->data = data;
  node->left = NULL;
  node->right = NULL;
 
  return(node);
}

void cerminkan(struct node* node)
{
  if (node==NULL)
    return;
  else
  {
    struct node* temp;
   

    cerminkan(node->left);
    cerminkan(node->right);

    temp        = node->left;
    node->left  = node->right;
    node->right = temp;
  }
}

void inOrder(struct node* node)
{
  if (node == NULL)
    return;
 
  inOrder(node->left);
  cout << node->data << " ";

  inOrder(node->right);
}


int main()
{
  struct node *root = simpul(4);
  root->left = simpul(5);
  root->right= simpul(6);
  root->left->left  = simpul(10);
  root->left->right = simpul(20);
  root->right->right = simpul(30);
  cout << "BST : ";
  inOrder(root);
  cerminkan(root);
  cout << endl << "BST CERMINAN: ";
  inOrder(root);
  getchar();
  return 0;
}

Author image
About the Author :

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum.

Connect with him on :