-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_list.cpp
More file actions
54 lines (43 loc) · 1001 Bytes
/
test_list.cpp
File metadata and controls
54 lines (43 loc) · 1001 Bytes
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
// Created by Abhishek Bhargava on 1/7/17.
// Copyright © 2017 Abhishek Bhargava. All rights reserved.
#include <iostream>
#include <map>
#include <cstring>
#include <cstdlib>
#include <cstddef>
#include <cstdint>
#include <cinttypes>
#include <cctype>
#include "lib/xalloc.h"
#include "lib/contracts.h"
#include "lib/list.h"
//Testing list struct
using namespace std;
void int_free(void *ptr) {
free(ptr);
}
void print_int(void *ptr) {
int *a = (int*)ptr;
cout << *a;
}
int main() {
list_t L = new_list(&int_free, &print_int);
int *a = (int*)xmalloc(sizeof(int));
*a = 5;
node_t N = new_node((void*)a);
add(L, N);
int *b = (int*)xmalloc(sizeof(int));
*b = 10;
node_t M = new_node((void*)b);
add_bottom(L, M);
remove_top(L);
remove_top(L);
M = new_node((void*)b);
add(L, M);
N = new_node((void*)a);
add_bottom(L, N);
cout << get_size(L) << endl;
print_list(L);
free_list(L);
return 0;
}