home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_09_06
/
9n06062a
< prev
next >
Wrap
Text File
|
1991-02-25
|
2KB
|
109 lines
//
// TryThing -- Test stub for Thing and
// -- ThingList classes.
// --
// -- Also uses overloaded global
// -- new and delete operators
// -- to aid in debugging.
//
// Version 1.01 -- 2/25/91
//
// Michael Kelly -- Author
//
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "hsort.hpp"
#include "th_int.hpp"
#include "th_long.hpp"
#include "th_doubl.hpp"
#include "th_struc.hpp"
#include "th_list.hpp"
#define N 5
a_struct my_struct[ N ] = {
{ "mike", 3 },
{ "tom", 2 },
{ "joe", 5 },
{ "jim", 1 },
{ "frank", 0 }
};
unsigned iterations;
int i;
void action()
{
ThingList thing_list;
IntThing int_thing[ N ] = { 103, 29, 89, 55, 15 };
DoubleThing double_thing[ N ] = { 5.3, 8.7, 0.01, 3.1416, 0.0 };
LongThing long_thing[ N ] = { 500L, 2L, 85L, 909L, 6L };
StructThing struct_thing[ N ] = {
my_struct[ 0 ], my_struct[ 1 ], my_struct[ 2 ],
my_struct[ 3 ], my_struct[ 4 ] };
if( int_thing[ 0 ].sortable() )
heapsort( N, int_thing );
if( long_thing[ 0 ].sortable() )
heapsort( N, long_thing );
if( double_thing[ 0 ].sortable() )
heapsort( N, double_thing );
if( struct_thing[ 0 ].sortable() )
heapsort( N, struct_thing );
for( i = 0; i < N; ++i )
if( ! thing_list.add( int_thing[ i ] ) ) {
printf("\n\tCould not add a Thing to the list!\n");
return;
}
for( i = 0; i < N; ++i )
if( ! thing_list.add( long_thing[ i ] ) ) {
printf("\n\tCould not add a Thing to the list!\n");
return;
}
for( i = 0; i < N; ++i )
if( ! thing_list.add( double_thing[ i ] ) ) {
printf("\n\tCould not add a Thing to the list!\n");
return;
}
for( i = 0; i < N; ++i )
if( ! thing_list.add( struct_thing[ i ] ) ) {
printf("\n\tCould not add a Thing to the list!\n");
return;
}
iterations = thing_list.iterate( &Thing::print );
printf(
"\n\t %u iterations "
"of print() method performed\n",
iterations
);
thing_list.ThingList::~ThingList();
for( i = N - 1; i >= 0; --i )
struct_thing[ i ].StructThing::~StructThing();
for( i = N - 1; i >= 0; --i )
double_thing[ i ].DoubleThing::~DoubleThing();
for( i = N - 1; i >= 0; --i )
long_thing[ i ].LongThing::~LongThing();
for( i = N - 1; i >= 0; --i )
int_thing[ i ].IntThing::~IntThing();
}
int main(void)
{
action();
return 0;
}