Thursday, July 27, 2017

lel

int LLcycle(list_t* list)
{
  element_t* el1 = list->head;
  element_t* el2 = list->head->next;
  while(1){
    // NULL is detected - no cycle
    if(el1->next == NULL || el2->next == NULL){
      return 0;
    }
    if(el1 == el2){ //el2 is the same address as el1
      return 1;
    }
    el1 = el1->next;
    el2 = el2->next->next;
  }
}

No comments:

Post a Comment