• Check out world news on HeadLinesList.com
  • Forum registration is now open for public.
Hello There, Guest! Login


Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to write Bucket Sorting in C?
#
I need to write a C program that performs bucket sorting, with given data structure

typedef struct node *node_ptr;
struct node{
int a;
int b;
int n;
node_ptr next;
};

and array of buckets
node_ptr buckets[10000];
node_ptr buckets_rear[10000]; (needed to add efficiently at rear)

Given the 10 input as following:
(Input format: a, b, n)
0 2 5
0 3 5
0 4 2
0 6 5
1 3 4
1 4 5
2 4 12
2 5 9
3 6 6
5 6 12

The program will do bucket sort based on n

I'm clueless on this. Help me please ?

If someone can code it up, I'll award 10 points, thanks in advance !
Sorted result should be:
0 4 2
1 3 4
0 2 5
0 3 5
0 6 5
1 4 5
3 6 6
2 5 9
2 4 12
5 6 12

Ads

#
Bucket sort is possibly the simplest distribution sorting algorithm. The essential requirement is that the size of the array from which the elements to be sorted are drawn is a small, fixed constant, say n.

This sort is easy to implement here is some psuedocode to guide you:

void bucketSort(int array[], int n) {
int i, j;
int count[n];
//initialize counters
//count amount of each array-number
//rearrange order of array
}

Ads

  


Forum Jump:


1 Guest(s)