185k views
1 vote
You can sort a large array of integers that are in the range 1 to 100 by using an array count of 100 items to count the number of occurrences of each integer in the array. Fill in the details of this sorting algorithm, which is called a bucket sort, and write a C function that implements it. What is the order of the bucket sort

1 Answer

4 votes

Answer:

See explaination

Step-by-step explanation:

#include<iostream>

using namespace std;

void bucketSort(int arr[],int size)

{

int count[101]={0};

for(int i=0;i<size;i++)

count[arr[i]]++;

int k=0;

for(int i=1;i<=100;i++)

{

while(count[i]>0)

{

arr[k++]=i;

count[i]--;

}

}

}

int main()

{

int arr[]={1,2,5,4,3,9,8,7,6};

bucketSort(arr,9);

for(int i=0;i<9;i++)cout<<arr[i]<<" ";

cout<<"\\";

}

User Reiswindy
by
5.7k points