diff Histogram.c @ 6:a2388fae93ff

Merge addInterval version with VMS__malloc version
author SeanHalle
date Thu, 11 Nov 2010 05:45:08 -0800
parents 13b8591dd045 83a412f2ef98
children fa6a281bd854
line diff
     1.1 --- a/Histogram.c	Thu Nov 11 05:37:07 2010 -0800
     1.2 +++ b/Histogram.c	Thu Nov 11 05:45:08 2010 -0800
     1.3 @@ -5,9 +5,8 @@
     1.4   * Author: seanhalle@yahoo.com
     1.5   *
     1.6   */
     1.7 -
     1.8 +#include <stdio.h>
     1.9  #include "Histogram.h"
    1.10 -#include <malloc.h>
    1.11  
    1.12  
    1.13  /*This Histogram Abstract Data Type has a number of bins plus a range of
    1.14 @@ -24,12 +23,14 @@
    1.15  
    1.16  Histogram *
    1.17  makeHistogram( int32 numBins, int32 startOfRange, int32 endOfRange )
    1.18 +
    1.19   {
    1.20     Histogram *hist;
    1.21     int32 i;
    1.22  
    1.23 -   hist = malloc( sizeof(Histogram) );
    1.24 -   hist->bins = malloc( numBins * sizeof(int32) );
    1.25 +
    1.26 +   hist = VMS__malloc( sizeof(Histogram) );
    1.27 +   hist->bins = VMS__malloc( numBins * sizeof(int32) );
    1.28  
    1.29     hist->numBins      = numBins;
    1.30     hist->binWidth     = (endOfRange - startOfRange) / numBins;
    1.31 @@ -79,6 +80,7 @@
    1.32   {
    1.33     int32 binIdx, i, numBars, maxHeight, barValue, binStart, binEnd;
    1.34  
    1.35 +
    1.36     maxHeight = 0;
    1.37     for( i = 0; i < hist->numBins; i++ )
    1.38      {
    1.39 @@ -86,7 +88,7 @@
    1.40      }
    1.41     barValue = maxHeight / 60;  //60 spaces across page for tallest bin
    1.42  
    1.43 -   printf("histogram: \n");
    1.44 +   printf( "histogram: \n" );
    1.45     if( barValue == 0 ) printf("error printing histogram\n");
    1.46     for( binIdx = 0; binIdx < hist->numBins; binIdx++ )
    1.47      {
    1.48 @@ -104,3 +106,9 @@
    1.49      }
    1.50   }
    1.51  
    1.52 +void
    1.53 +freeHist( Histogram *hist )
    1.54 + {
    1.55 +   VMS__free( hist->bins );
    1.56 +   VMS__free( hist );
    1.57 + }