-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_slice.c
49 lines (37 loc) · 996 Bytes
/
test_slice.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
#include <pylists4c.h>
int main()
{
LIST* pList = NULL;
LIST* pSlice = NULL;
listSetFatalMallocErrors(TRUE);
pList = list("0, 1, 2, 3, 4, 5, 6, 7, 8, 9");
printf("list=");
listPrint(pList);
pSlice = listSlice(pList, 1, 9);
printf("list[1:9]=");
listPrint(pSlice);
listClear(&pSlice);
pSlice = listSliceTo(pList, 5);
printf("list[:5]=");
listPrint(pSlice);
listClear(&pSlice);
pSlice = listSliceFrom(pList, 5);
printf("list[5:]=");
listPrint(pSlice);
listClear(&pSlice);
pSlice = listSlice(pList, -9, -1);
printf("list[-9:-1]=");
listPrint(pSlice);
listClear(&pSlice);
pSlice = listSliceTo(pList, -5);
printf("list[:-5]=");
listPrint(pSlice);
listClear(&pSlice);
pSlice = listSliceFrom(pList, -5);
printf("list[-5:]=");
listPrint(pSlice);
listClear(&pSlice);
listClear(&pList);
printf("\nAllocated memory: %lu\n", listGetAllocatedMemory());
return 0;
}