-
Notifications
You must be signed in to change notification settings - Fork 0
/
test1.c
56 lines (44 loc) · 1.41 KB
/
test1.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
#include <stdio.h>
#include <stdlib.h>
#include "list.h"
int main( int argc, char **argv )
{
int i,j;
struct Performance *performance;
struct Node *list;
struct Node **list_ptr;
list = NULL;
performance = newPerformance();
printf( "isEmpty = %d\n", isEmpty( performance, &list ) );
// should print 1
// should print isEmpty=0 and j increasing from 0 to 9
for (i=0;i<10;i++)
{
printf( "%d: ", i );
push( performance, &list, &i, sizeof( int ) );
readHead( performance, &list, &j, sizeof(int) );
printf( "isEmpty = %d, ", isEmpty( performance, &list ) );
// should print 0
printf( "j = %d\n", j );
}
// should print j decreasing from 9 to 0 and isEmpty = 0
for ( list_ptr=&list; (!isEmpty(performance,list_ptr)); list_ptr=next(performance,list_ptr) )
{
readHead( performance, list_ptr, &j, sizeof(int) );
printf( "%d, ", j );
}
printf( "isEmpty = %d\n", isEmpty( performance, &list ) );
// should print j decreasing from 9 to 0 and isEmpty = 1
while (!isEmpty(performance,&list))
{
pop( performance, &list, &j, sizeof(int) );
printf( "%d, ", j );
}
printf( "isEmpty = %d\n", isEmpty( performance, &list ) );
printf( "reads: %5d\n", performance->reads );
printf( "writes: %5d\n", performance->writes );
printf( "mallocs: %5d\n", performance->mallocs );
printf( "frees: %5d\n", performance->frees );
free( performance );
return 0;
}