Take Maximum Node Make it Root Node

Take Maximum Node Make it Root Node and attach rest of tree with it so that BST Property will not volatilized #include#includeclass Node{private: int data,i; Node* right,*q,*p; Node* left;public: Node(){ root=NULL; right=left=NULL; }Node *root; Node* remove(Node *root, int value){ Node *t; int cmpr = value – root->data; if (cmpr < 0){ t = remove(root->left, value); root->leftContinue reading “Take Maximum Node Make it Root Node”

Find Minimum node make it Root node attach rest of Tree with it such that BST property is not violated

Find Minimum node make it Root node attach rest of Tree with it such that BST property is not violated #include#includeclass Node{private: int data,i; Node* right,*q,*p; Node* left;public: Node(){ root=NULL; right=left=NULL; }Node *root;Node* remove(Node *root, int value){ Node *t; int cmpr = value – root->data; if (cmpr < 0){ t = remove(root->left, value); root->left = t;Continue reading “Find Minimum node make it Root node attach rest of Tree with it such that BST property is not violated”

Traverse Tree According To User Value :Get Value From User ☻ :~C++ Code Tree

Traverse Tree According To User Value :Get Value From User ☻#include#includeclass Node{private: int data; Node* right,*q,*p; Node* left;public: Node(){ root=NULL; right=left=NULL; }Node *root; void insert(int data){ Node* newnode = new Node(); newnode->data = data; if (root == NULL){ root=newnode; return; } Node *p,*q; p=q=root; while (q!=NULL){ p=q; if (newnode->data> q->data) q = q->right; else qContinue reading “Traverse Tree According To User Value :Get Value From User ☻ :~C++ Code Tree”

Traverse Left Subtree with Post Order and Right Sub tree with PreOrder ~ C++ Codes Tree

Traverse root left sub tree with post order ☻and then print root ☻and then root right sub tree with pre order ☻ #include#includeclass Node{private: int data; Node* right,*q,*p; Node* left;public: Node(){ root=NULL; right=left=NULL; }Node *root; void insert(int data){ Node* newnode = new Node(); newnode->data = data; if (root == NULL){ root=newnode; return; } Node *p,*q;Continue reading “Traverse Left Subtree with Post Order and Right Sub tree with PreOrder ~ C++ Codes Tree”

Insert A Value on Left Side which is greater Then Root and Small Value on Right side ~ C++ Tree codes

Insert A Value on Left Side which is greater Then Root and Small Value on Right side #include #include class Node{ private: int data; Node* right,*q,*p; Node* left; public: Node(){ root=NULL; right=left=NULL; }Node *root; void insert(int data){ Node* newnode = new Node(); newnode->data = data; if (root == NULL){ root=newnode; return; } Node *p,*q; p=q=root;Continue reading “Insert A Value on Left Side which is greater Then Root and Small Value on Right side ~ C++ Tree codes”

Convert Left subtree into right subtree and right into left in tree C++ code: ~ BST

Convert Left Sub Tree of a Root into Right Sub Tree and Right sub Tree into Left Sub Tree ☺ ☻#include#includeclass Node{private: int data; Node* right,*q,*p; Node* left;public: Node(){ root=NULL; right=left=NULL; }Node *root; void insert(int data){ Node* newnode = new Node(); newnode->data = data; if (root == NULL){ root=newnode; return; } Node *p,*q; p=q=root; while (q!=NULL){Continue reading “Convert Left subtree into right subtree and right into left in tree C++ code: ~ BST”

Swapping Without Temporary variable C++

Swap Two No without using any temporary variable #include#includevoid main(){clrscr();int a,b;cout<<"\n\n——–Program To Swap Two Numbers without Temprary veriale——-\n\n";cout<<"\n\nEnter First No: ";cin>>a;cout<<"\n\nEnter Secont No: ";cin>>b;cout<<"\n\nA= "<<a<<" B= "<<b;cout<<"\n\n———-Swap————-\n\n";a=a+b;b=a-b;a=a-b;cout<<"\n\nA= "<<a<<" B=  "<<b;getch();}

BST (Binary Search Tree) in C++

Creation of BST(binary Search Tree),Insertion at any point,Deletion At any point,Maximum Value,Minimum Value,Searching in tree [[Important Data Structure Codes in C++]]Tree Non Liner Data Structure#include#includeclass Node{private: int data; Node* right; Node* left;public: Node(){ root=NULL; right=left=NULL; }Node *root; void insert(int data){ Node* newnode = new Node(); newnode->data = data; if (root == NULL){ root=newnode; return; } NodeContinue reading “BST (Binary Search Tree) in C++”

C++ Program to print Hexagonal Shape

#include#includevoid main(){   int d=0,b=0;clrscr();for(int i=9;i<=19;i++){gotoxy(i,12);cout<<char(2);}for(int j=9;j<=19;j++){gotoxy(j,26);cout<<char(2);}d=9;for( b=8;b<=14;b++){d=d-1;gotoxy(d,b+5);cout<<char(2);} d=19;for( b=18;b<=24;b++){d=d+1;gotoxy(d,b-5);cout<<char(2);} d=9;for( b=20;b>=14;b–){d=d-1;gotoxy(d,b+5);cout<<char(2);}d=27;for( b=14;b<=20;b++){d=d-1;gotoxy(d,b+5);cout<<char(2);}cout<<"\n\n\n\n Who's it is 🙂 . . . .";getch();}

Binary Search ~ Program to search a value from array using Binary search

#include#include void binary_search(int *A,int value,int s,int e); void display(int *arr,int count){for(int i=0;i<count;i++){ cout<<arr[i]<<"\t";}}void binary_search(int *A,int value,int s,int e){int mid=0;mid=(s+e)/2;if(value==A[mid]){ cout<<"\nValue found\n"; }else if(value>A[mid]){ s=mid+1; binary_search(A,value,s,e);}else if(value<A[mid]){e=mid-1;binary_search(A,value,s,e);}else{ cout<<"not found";}} void main(){clrscr();int A[]={5,4,9,7,8,1,3,2,6},value=0;cout<<"\nEnter Value You Want to Search: ";cin>>value;binary_search(A,value,0,9);cout<<"\n\nArray is following:\n";display(A,9); getch();}