Wednesday, July 26, 2017

cycle

void cycle(LL_t* list, int n, int m)
{
  element_t* elN = list->head;
  element_t* elM = list->head;
  unsigned int i= 0;
  unsigned int j =0;

  while(i < n){ //iterates through the list for n
    if(i == n-1){ // this is the index of the nth node that you want
      while(j < m){
        if(j == m-1){ // finds the mth node
          elN->next = elM; //the next pointer of the nth node is the address of m
        }
        j++;
        elM = elM->next;
      }
    }
    i++;
    elN = elN->next;
  }
}

No comments:

Post a Comment