-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdll-1-13.c
74 lines (72 loc) · 1.85 KB
/
dll-1-13.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 "dll.h"
#include "integer.h"
extern void srandom(unsigned int);
extern long int random(void);
int
main(void)
{
srandom(1014);
DLL *p = newDLL(displayINTEGER,freeINTEGER);
DLL *q = newDLL(displayINTEGER,freeINTEGER);
unionDLL(p,q);
/* do some inserts */
int i;
for (i = 0; i < 10000; ++i)
{
int x = random() % (sizeDLL(p) + 1);
int j = random() % 100;
insertDLL(p,x,newINTEGER(j));
}
/* do some inserts */
for (i = 0; i < 10000; ++i)
{
int x = random() % (sizeDLL(q) + 1);
int j = random() % 100;
insertDLL(q,x,newINTEGER(j));
}
/* now a bunch of unions */
printf("starting 1000000 unions\n");
for (i = 0; i < 1000000; ++i)
{
unionDLL(q,p);
unionDLL(p,q);
}
/* do some more inserts */
for (i = 0; i < 10000; ++i)
{
int x = random() % (sizeDLL(q) + 1);
int j = random() % 100;
insertDLL(q,x,newINTEGER(j));
}
if (sizeDLL(p) < 100)
{
printf("p: ");
displayDLL(p,stdout);
printf("\n");
printf("p (debug): ");
displayDLLdebug(p,stdout);
printf("\n");
printf("\n");
}
if (sizeDLL(q) < 100)
{
printf("q: ");
displayDLL(q,stdout);
printf("\n");
printf("q (debug): ");
displayDLLdebug(q,stdout);
printf("\n");
printf("\n");
}
printf("size of p is %d\n",sizeDLL(p));
printf("size of q is %d\n",sizeDLL(q));
printf("value at 6445 is %d\n",getINTEGER(getDLL(p,6445)));
printf("setting value at 6445 to 9\n");
freeINTEGER(setDLL(p,6445,newINTEGER(9)));
printf("value at 6445 now is %d\n",getINTEGER(getDLL(p,6445)));
freeDLL(p);
freeDLL(q);
return 0;
}