Back to Browse

Data Structures using C Part 23 - Binary search trees and operations | Binary Search Tree c program

5.2K views
Jun 9, 2017
15:57

Binary Search Tree Binary Search Tree is a binary tree in which left subtree of every node contains smaller values and right subtree contains larger values. i.e., All the nodes on the left of root node have values lesser than root node and all the nodes on the right of root node have values greater than root node. No two nodes can have the same value stored in them. Here a value stored in a node is also called as key. Representation Operations on BST Find Insert Delete Find in Binary search tree (BST) struct bstNode *Find(struct bstNode *root, int data) { if(root == NULL) return(NULL); if(data lessthan root- greaterthan info) return(Find(root- greaterthan left, data)); else if(data greaterthan root- greaterthan info) return(Find(root- greaterthan right,data)); return(root); } Insert in Binary search tree (BST) : void insert(struct bstNode *root, int data) { struct bstNode *node; struct bstNode *n = malloc(sizeof(struct bstNode)); n- greaterthan left = NULL; n- greaterthan info = data; n- greaterthan right = NULL; if(root == NULL) root=n; else { node = root; while(node != NULL) { if(node- greaterthan info greaterthan data) { if(node- greaterthan left == NULL) { node- greaterthan left=n; node = NULL ; } node=node- greaterthan left; } else if(node- greaterthan info lessthan data) { if(node- greaterthan right == NULL) { node- greaterthan right=n; node = NULL ; } node=node- greaterthan right; } } } } ankpro ankpro training Asp.net MVC C# C sharp Bangalore Rajajinagar Selenium Coded UI Mobile automation testing Mobile testing JQuery JavaScript .Net C C++ Components of the .Net framework Hello World Literal Keywords Variable Data types Operators Branching Loops Arrays Strings Structures Enums Functions

Download

0 formats

No download links available.

Data Structures using C Part 23 - Binary search trees and operations | Binary Search Tree c program | NatokHD