#include <cstdlib>
#include <iostream>
using namespace std;
#include “header.h”
int main(int argc, char *argv[])
{
cout << “Roll No. mc100200752\n\nAssignment: CS301 – 4\n\n”;
cout << “Question:\nWrite a program in c++ that takes any no”;
cout << ” of elements through command prompt from”;
cout << “user and saves it in an array. Then convert it into sorted format with”;
cout << ” minimum heap sort using your own coded implementation.\n\nAnswer:\n\n”;
int no,elements[no],i=0,j=0;
cout << “Enter no. of elements you want?: “; cin >> no;
cout << “This program will get ” << no << ” no of elements and then will convert them into sorted formate with min heap.\n\n”;
for(i;i<no;i++)
{
cout << “\nPlease enter any numeric value: “;
cin >> elements[i];
}
cout << “\n\nHere is the sorted format with min heap:\n\n”;
minimum(elements,no);
cout << “\n\n”;
system(“PAUSE”);
return EXIT_SUCCESS;
}
//Include File: #include “header.h”
int minimum(int arr[],int no)
{
int temp;
for(int i=0;i<no;i++)
{
for(int j=0;j<(no-i);j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
for(int i=0;i<no;i++)
{
cout<<arr[i]<<” “;
cout<<endl;
}
return 1;
}
Last updated: March 19, 2014