-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest6.c
75 lines (57 loc) · 1.5 KB
/
test6.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include <stdlib.h>
#include "array.h"
/* This program will fill an array of doubles of size 100 with the first
* 20 non-negative integers.
*/
#define CAPACITY 100 // total capacity of the array
#define NEL 20 // number of elements of the series to include
int main( int argc, char **argv )
{
int i;
double number;
struct Performance *perf;
struct Array *array;
perf = newPerformance();
array = newArray( perf, sizeof( double ), CAPACITY );
for (i=0;i<NEL;i++)
{
number = i;
appendItem( perf, array, &number );
}
printf( "Initial array:\n" );
for (i=0;i<array->nel;i++)
{
readItem( perf, array, i, &number );
printf( "%d %f\n", i, number );
}
number = 7.5;
insertItem( perf, array, 8, &number );
printf( "After insert:\n" );
for (i=0;i<array->nel;i++)
{
readItem( perf, array, i, &number );
printf( "%d %f\n", i, number );
}
number = -1.0;
prependItem( perf, array, &number );
printf( "After prepend:\n" );
for (i=0;i<array->nel;i++)
{
readItem( perf, array, i, &number );
printf( "%d %f\n", i, number );
}
deleteItem( perf, array, 16 );
printf( "After delete:\n" );
for (i=0;i<array->nel;i++)
{
readItem( perf, array, i, &number );
printf( "%d %f\n", i, number );
}
freeArray( perf, array );
printf( "reads: %5d\n", perf->reads );
printf( "writes: %5d\n", perf->writes );
printf( "mallocs: %5d\n", perf->mallocs );
printf( "frees: %5d\n", perf->frees );
free( perf );
}