Selection Sort code in C++

 Other Type Of Sorting : Click here :: most important :: #include#includevoid display(int *arr,int size){ cout<<endl; for(int i=0;i<=size;i++){ cout<<arr[i]<<"\t";     }} int find_min_index(int *arr,int start,int n){ int posmin=start; int index; for(index=start;index<=n;index++){ display(arr,n); if(arr[index]<arr[posmin]){ posmin=index; cout<<"\n Min index = "<<posmin<<"\t Value = "<<arr[posmin]<<"\n"; } }return posmin;} void selection_sort(int *arr,int n){ int posmin,count,temp; for(count=0;count<=n;count++) { posmin=find_min_index(arr,count,n); temp=arr[posmin]; arr[posmin]=arr[count]; arr[count]=temp; }} void main(){int x[]={12,5,7,1,9,4,8};clrscr();selection_sort(x,6);display(x,6);getch();}

Insertion Sort Code in C++

 Other Type Of Sorting : Click here :: most important :: #include#include void display(int *arr,int n){ cout<<endl; for(int i=0;i<=n;i++){ cout<<arr[i]<<"\t";  }} void insertion_sort(int *arr,int n){ int pos,count,val; for(count=1;count<=n;count++) { val=arr[count]; for(pos=count-1;pos>=0;pos–) { if(arr[pos]>val)     { cout<<"\n Swapped arr["<<pos+1<<"] with arr["<<pos<<"]\n"; arr[pos+1]=arr[pos]; } else { break; }; } arr[pos+1]=val; display(arr,6); }} void main(){int x[]={12,4,7,2,9,5,1};clrscr();display(x,6);insertion_sort(x,6);getch();}

Bubble Sort Code in C++

 Other Type Of Sorting : Click here :: most important :: #include#include void display(int *arr,int n){ cout<<endl; for(int i=0;i<=n;i++){ cout<<arr[i]<<"\t";  }} void bubblesort(int *arr,int n){ int i,temp,bound=n-1; int swapped=1; while(swapped>0) { swapped=0; for(i=0;i<=bound;i++){ display(arr,6); if(arr[i]>arr[i+1]){  cout<<endl<<"Swaped arr["<<i<<"] with arr["<<i+1<<"]\n"; temp=arr[i]; arr[i]=arr[i+1]; arr[i+1]=temp; swapped=i;          }} bound=swapped; }} void main(){int x[]={12,7,5,4,11,9,8};clrscr();bubblesort(x,6);display(x,6);getch();}

Trees in C++

Implementation of Binary Tree …. In-Order TraversalPre-Order TraversalPost-Order Traversal#include#includeclass treenode{public:int info;treenode *left,*right;treenode(){ this->info=NULL;  this->left=NULL;  this->right=NULL;}treenode(int info){ this->info=info;  this->left=NULL;  this->right=NULL;}void setinfo(int info){ this->info=info; }int getinfo(){ return info; }void setleft(treenode *left){  this->left=left; }void setright(treenode *right){   this->right=right; }treenode *getleft(){ return left; }treenode *getright(){  return right; }void insert(treenode *root,int info){treenode *node=new treenode(info);treenode *p,*q;p=q=root;while(info!=p->getinfo() && q!=NULL){p=q;if(info getinfo()){ q=p->getleft(); }else{  q=p->getright(); }}if(info==p->getinfo()){Continue reading “Trees in C++”

Data Structure Programs

“All Data Structure Programs up-till now” To get code Click on that program heading 🙂 ☺ ☻   ALL Type Of Sorting : Click here :: most important ::  ——————- TREES:-   RED AND BLACK TREE IN C++Insertion- Deletion- Searching -Max,Min Tree C++ Code Tree Non Liner Data Structure    Insert 100 in all Leaf nodes and 10 in all nonContinue reading “Data Structure Programs”