forked from seeditsolution/cprogram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathALGO_BUCKETSORT
More file actions
49 lines (38 loc) · 721 Bytes
/
ALGO_BUCKETSORT
File metadata and controls
49 lines (38 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
//Bucket Sort Program when integers are floating point numbers in some range
void bucketSort(float *arr,int n)
{
vector<float> b[n];
int i,j;
for(i=0;i<n;i++){
int bi=n*arr[i];
b[bi].push_back(arr[i]);
}
for(i=0;i<n;i++)
{
sort(b[i].begin(),b[i].end());
}
int index=0;
for(i=0;i<n;i++)
{
for(j=0;j<b[i].size();j++)
arr[index++]=b[i][j];
}
}
int main(){
int n;
float arr[200];
cout<<"Enter N : ";
cin>>n;
int i;
for(i=0;i<n;i++)
cin>>arr[i];
bucketSort(arr,n);
cout<<"Sorted Array"<<endl;
for(i=0;i<n;i++)
cout<<arr[i]<<endl;
return 0;
}