xref: /llvm-project/lldb/test/API/python_api/value/linked_list/main.cpp (revision fdea9a4ec9b0d9585b8fe8a612686d9f44f40ddc)
1 #include <stdio.h>
2 
3 class Task {
4 public:
5     int id;
6     Task *next;
Task(int i,Task * n)7     Task(int i, Task *n):
8         id(i),
9         next(n)
10     {}
11 };
12 
13 
main(int argc,char const * argv[])14 int main (int argc, char const *argv[])
15 {
16     Task *task_head = NULL;
17     Task *task1 = new Task(1, NULL);
18     Task *task2 = new Task(2, NULL);
19     Task *task3 = new Task(3, NULL); // Orphaned.
20     Task *task4 = new Task(4, NULL);
21     Task *task5 = new Task(5, NULL);
22 
23     task_head = task1;
24     task1->next = task2;
25     task2->next = task4;
26     task4->next = task5;
27 
28     int total = 0;
29     Task *t = task_head;
30     while (t != NULL) {
31         if (t->id >= 0)
32             ++total;
33         t = t->next;
34     }
35     printf("We have a total number of %d tasks\n", total);
36 
37     // This corresponds to an empty task list.
38     Task *empty_task_head = NULL;
39 
40     Task *task_evil = new Task(1, NULL);
41     Task *task_2 = new Task(2, NULL);
42     Task *task_3 = new Task(3, NULL);
43     task_evil->next = task_2;
44     task_2->next = task_3;
45     task_3->next = task_evil; // In order to cause inifinite loop. :-)
46 
47     return 0; // Break at this line
48 }
49