Bucket
Bucket sort an array of integer values into ascending numerical order.
Controller: CodeCogs
Contents
Interface
C++
BucketSort
template<class T> voidbucketSort( | T* | vals | |
unsigned int | n | ||
T | lo | ||
T | hi | ) |
Example 1
#include <stdlib.h> #include <time.h> #include <codecogs/computing/sort/bucket.h> int main() { int vals[25]; int n=25; srand(time(0)); for (int i=0; i<n; i++) vals[i]=(int)((double) n*rand())/RAND_MAX; printf("\nArray to be sorted:\n"); for (int i=0; i<n; i++) printf("%i ", vals[i]); printf("\n"); Array::Sort::bucketSort<int>(vals, n, 0, 25); printf("Sorted array:\n"); for (int i=0; i<n; i++) printf("%i ", vals[i]); printf("\n"); return 0; }
Output:Array to be sorted: 12 23 10 23 4 2 9 19 14 16 22 5 7 16 1 6 8 24 13 21 9 17 1 3 6 Sorted array: 1 1 2 3 4 5 6 6 7 8 9 9 10 12 13 14 16 16 17 19 21 22 23 23 24
Parameters
vals the array of values to be sorted n the number of items in the array lo the lowest input value in the array hi the highest input value in the array
Authors
- James Warren (July 2005)
Source Code
Source code is available when you buy a Commercial licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.