/* Linked lists * 15-122 Principles of Imperative Programming, Fall 2010 * Frank Pfenning */ // type elem must be defined typedef int elem; struct list { elem data; struct list* next; }; typedef struct list* list; bool is_segment(list start, list end) { list p = start; while (p != end) { if (p == NULL) return false; p = p->next; } return true; } bool is_circular(list l) { if (l == NULL) return false; { list t = l; // tortoise list h = l->next; // hare while (t != h) //@loop_invariant is_segment(t, h); { if (h == NULL || h->next == NULL) return false; t = t->next; h = h->next->next; } return true; } }