Skip to content

Instantly share code, notes, and snippets.

@swapnil-warke
Created August 1, 2013 18:55
Show Gist options
  • Save swapnil-warke/6134158 to your computer and use it in GitHub Desktop.
Save swapnil-warke/6134158 to your computer and use it in GitHub Desktop.
basic code supposed to be ur library code
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
using namespace std;
typedef long long ll;
template <class T>
void Merge(T a[],T temp[],ll low,ll high)
{
ll mid=(high+low)/2;
ll i=low;
ll j=mid+1;
ll k=low;
while(i<=mid && j<=high)
{
if(a[i]<=a[j])
temp[k++]=a[i++];
else
temp[k++]=a[j++];
}
while(i<=mid) temp[k++]=a[i++];
while(j<=high) temp[k++]=a[j++];
//copy back temp in
for(ll z=low;z<=high;z++) a[z]=temp[z];
}
template <class T>
void MergeSort(T a[],T temp[],ll low,ll high)
{
if(low<high)
{
ll mid=(low+high)/2;
MergeSort(a,temp,low,mid);
MergeSort(a,temp,mid+1,high);
Merge<T>(a,temp,low,high);
}
}
int main()
{
float a[100],t[100];
for(int i=1;i<=5;i++)
cin>>a[i];
MergeSort<float>(a,t,1,5);
for(int i=1;i<=5;i++)
cout<<a[i]<<" ";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment