Sorting/PointerBased/bucketArraySortPtr.c File Reference

Define core driver for Bucket Sort, pending the proper hash() and numBuckets() implementations, using arrays. To employ Bucket Sort you only need to (a) provide a meaningful hash () method to return an integer given an element; and (b) provide a method to compute the number of buckets to use. This code acts as the driver and relies on external code to provide the domain-specific coding. More...

#include <stdlib.h>
#include "report.h"
#include "bucketArraySortPtr.h"

Functions

static void insert (BUCKET *bucket, void *elt)
 Insert into bucket and extend as needed by doubling the size of the bucket array storage.
static void insertionSortPointers (void **ar, int n, int(*cmp)(const void *, const void *))
 Use Insertion Sort to sort the pointers in the bucket array.
void extract (BUCKET buckets[], int(*cmp)(const void *, const void *), void **ar)
 One by one remove and overwrite ar with proper values.
void sortPointers (void **ar, int n, int(*cmp)(const void *, const void *))
 Invoke BucketSort on the given array.

Variables

static BUCKETbuckets = 0
 Allocation of buckets and the number of buckets allocated.
static int num = 0
 Number of buckets.


Detailed Description

Define core driver for Bucket Sort, pending the proper hash() and numBuckets() implementations, using arrays. To employ Bucket Sort you only need to (a) provide a meaningful hash () method to return an integer given an element; and (b) provide a method to compute the number of buckets to use. This code acts as the driver and relies on external code to provide the domain-specific coding.

Author:
George Heineman
Date:
6/15/08

Function Documentation

void extract ( BUCKET  buckets[],
int(*)(const void *, const void *)  cmp,
void **  ar 
)

One by one remove and overwrite ar with proper values.

static void insert ( BUCKET bucket,
void *  elt 
) [static]

Insert into bucket and extend as needed by doubling the size of the bucket array storage.

static void insertionSortPointers ( void **  ar,
int  n,
int(*)(const void *, const void *)  cmp 
) [static]

Use Insertion Sort to sort the pointers in the bucket array.

void sortPointers ( void **  ar,
int  n,
int(*)(const void *, const void *)  cmp 
)

Invoke BucketSort on the given array.


Variable Documentation

BUCKET* buckets = 0 [static]

Allocation of buckets and the number of buckets allocated.

int num = 0 [static]

Number of buckets.

Algorithm Development Kit 1.0