Sorting/buildDoubleBasedInput.c File Reference

Driver to construct array of doubles for sorting. Build up a pointer-based array of Doubles to use as a basis for testing the various sorting algorithms. More...

#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <stdio.h>
#include <math.h>
#include "buildDoubleBasedInput.h"
#include "problem.h"
#include "report.h"

Functions

int doubleComp (double *a1, double *a2)
 comparator function for double elements.
int ascending (double *a1, double *a2)
 comparator function for ascending order.
int descending (double *a1, double *a2)
 comparator function for descending order.
void killer (double *combined, int numElements)
 Implementation of killer-of-three median derived from: http://ralphunden.net/content/tutorials/a-guide-to-introsort/.
void prepareInput (int size, int argc, char **argv)
 Construct a random string of size ssize and have 'str1' and 'str2' be allocated strings with the same contents.
void postInputProcessing ()
 After sorting, can check whether sort succeeded.
void execute ()
 Execute by invoking malloc(numElements) a total of numT times.
void problemUsage ()
 No specific problem usage.

Variables

double ** values
 where input is located in memory.


Detailed Description

Driver to construct array of doubles for sorting. Build up a pointer-based array of Doubles to use as a basis for testing the various sorting algorithms.

Required Input:

  1. int numElements
  2. int verbose

Input flags:

  1. -a Numbers are sorted in ascending order
  2. -b Use BellCurve distribution for random data
  3. -k Killer 'median-of-3' as proposed by Musser, 1997
  4. -d Numbers are sorted in descending order
  5. -u n,o When paired with [a/d] determines number of pairs out of order, and distance of entity with which to swap
External API
  1. void problemUsage() shows what is expected
  2. void postInputProcessing() performs post-solution processing
  3. void prepareInput() prepare the input
  4. void execute() begin the problem

Author:
George Heineman
Date:
6/15/08

Function Documentation

int ascending ( double *  a1,
double *  a2 
)

comparator function for ascending order.

int descending ( double *  a1,
double *  a2 
)

comparator function for descending order.

int doubleComp ( double *  a1,
double *  a2 
)

comparator function for double elements.

void execute (  ) 

Execute by invoking malloc(numElements) a total of numT times.

.numElements

output sum to be sure is correct.

void killer ( double *  combined,
int  numElements 
)

Implementation of killer-of-three median derived from: http://ralphunden.net/content/tutorials/a-guide-to-introsort/.

Note that the data is contiguous and we must swap as required large sequence of bytes (oh well; it won't count against costs).

void postInputProcessing (  ) 

After sorting, can check whether sort succeeded.

void prepareInput ( int  size,
int  argc,
char **  argv 
)

Construct a random string of size ssize and have 'str1' and 'str2' be allocated strings with the same contents.

use character-swapping algorithm from strfry.c in glibc

http://www.koders.com/c/fidBD83E492934F9F671DE79B11E6AC0277F9887CF5.aspx

void problemUsage (  ) 

No specific problem usage.


Variable Documentation

double** values

where input is located in memory.

Algorithm Development Kit 1.0