1//===-- main.c --------------------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9#include <stdio.h> 10 11class Task { 12public: 13 int id; 14 Task *next; 15 Task(int i, Task *n): 16 id(i), 17 next(n) 18 {} 19}; 20 21 22int main (int argc, char const *argv[]) 23{ 24 Task *task_head = new Task(-1, NULL); 25 Task *task1 = new Task(1, NULL); 26 Task *task2 = new Task(2, NULL); 27 Task *task3 = new Task(3, NULL); // Orphaned. 28 Task *task4 = new Task(4, NULL); 29 Task *task5 = new Task(5, NULL); 30 31 task_head->next = task1; 32 task1->next = task2; 33 task2->next = task4; 34 task4->next = task5; 35 36 int total = 0; 37 Task *t = task_head; 38 while (t != NULL) { 39 if (t->id >= 0) 40 ++total; 41 t = t->next; 42 } 43 printf("We have a total number of %d tasks\n", total); 44 45 // This corresponds to an empty task list. 46 Task *empty_task_head = new Task(-1, NULL); 47 48 return 0; // Break at this line 49} 50