Showing posts with label heap. Show all posts
Showing posts with label heap. Show all posts

Sunday, November 30, 2014

Heap Sort (min heap)

Sorting Using min heap and arrange in decending order 


 Other Type Of Sorting : Click here :: most important ::


#include<iostream.h>
#include<conio.h>
#define max 7
class array{
int arr[max];
int count;
public:
array()
{
count=0;
for(int i=0;i<max;i++)
{ arr[i]=0; }
}
void add(int num){
if(count<max){
arr[count]=num; count++;}
else
{cout<<"\n Array is full"<<endl;}
}
void heapsort()
{
for(int i=count-1;i>0;i--)
{int ivalue=arr[i];
arr[i]=arr[0];
arr[0]=ivalue;
makeheap(i);}
}
void display()
{
for(int i=0;i<count;i++)
{ cout<<arr[i]<<"\t";}
}
void makeheap(int c)
{
for(int i=0;i<c;i++)
{
 int val=arr[i];
int s=i;
int f=(s-1)/2;
while(s>0 && arr[f]>val)
{ arr[s]=arr[f];
s=f;
f=(s-1)/2;}
arr[s]=val;
}
}
};
void main()
{
clrscr();
array a;
a.add(15);
a.add(19);
a.add(18);
a.add(7);
a.add(17);
a.add(16);
a.add(8);
cout<<"\n\n Values you insert in min order heap\n \n";
a.display();
a.makeheap(7);
cout<<"\n\n Values inserted in Heap tree\n\n";
a.display();
a.heapsort();
cout<<"\n\n Values after heap sort (min order)( desecnding )\n\n";
a.display();
getch();
}



Saturday, September 20, 2014

Data Structure Programs

Read Also:  


"All Data Structure Programs up-till now"

To get code Click on that program heading :) ☺ ☻ 

 ALL Type Of Sorting Click here :: most important :: 

-------------------

`Queues 

----------------

`Single Link-List:

*  How to create single Link-list in C++

*  Insertion at any point in link-list in C++

*  Concatenate or Merge two Link-lists in C++

Deletion At any point in Circular Link List in C++
------------------------------------

`Double Link-list:

=================

Stacks Data Structure:


Decimal to binary conversion using stack in c++
============ 

How to add two matrix size is define by use






Program to print counting 10 to 1 using Recursion

--------------------------------------------------