Consider a sorting algorithm for both heap and stl based program with two cases:
1st Case: it take O(n) to create a heap and O(log n) or O(k*log n) time to get maximal element(for k numbers) so the total complexity for such problem is O(n+ k*log n) and for larger input (log n) will become insignificant so overall complexity become O(n).
2nd Case: when we use STL to sort any sequence it takes O(n*log n) time complexity.
So now it cleared that we should use heap not only in sorting but also there are several examples where we can efficiently use it over STL.
See, I wrote code for heap and using stl both to sort a large sequence.
1st Using heap :
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int test;
scanf("%lld",&test);
vector<long long int> v(test);
for(long long int i=0;i<test;i++)
{
scanf("%lld",&v[i]);
}
make_heap(v.begin(),v.end());
sort_heap(v.begin(),v.end()); //sort using heap
for(long long int i=0;i<v.size();i++)
{
printf("%lld\n",v[i]);
}
return 0;
}
2nd Using STL :
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int test;
scanf("%lld",&test);
long long int v[test];
for(long long int i=0;i<test;i++)
{
scanf("%lld",&v[i]);
}
sort(v,v+test);
for(long long int i=0;i<test;i++)
{
printf("%lld\n",v[i]);
}
return 0;
}