Beispiel #1
0
int checkCycle(myList L )
{
    Node * slow = L.get_first() , * fast = L.get_first() ; 
    while(fast->next && slow){
        slow = slow->next  ; fast = fast->next->next ; 
        if(slow==fast)
        {
            slow = L.get_first() ; 
            int count = 0 ; 
            while(slow!=fast) {slow = slow->next ; fast = fast->next ; count ++ ;  }
            return count + 1 ; 
        }
    }
    return 0 ;
}
Beispiel #2
0
void makeCycle(myList L , int joint ){
    Node * temp = L.get_first() ; 
    Node * jointptr = L.get_head() ; 
    while(joint-- && jointptr) jointptr= jointptr->next ; 
    while(temp && temp->next) temp = temp->next ; 
    temp->next = jointptr ; 
}
Beispiel #3
0
void even_odd_merge(myList L )
{
    if(! L.get_first()->next) return ;
    Node * even = L.get_first() , *  odd = L.get_first()->next , *node_1 = L.get_first()->next ; 

    while(even&& odd)
    {
        even->next = odd->next ; 
        if(! even->next) break ; 
        even = even->next ;

        odd->next = even->next ; 
        odd = odd->next ; 
    }

    even->next =  node_1 ; 
}