Horje
divide a linked list into three parts based on their position mod 3. Code Example
divide a linked list into three parts based on their position mod 3.
int split_list(struct node *ll)
{
    struct node *l1, *l2, *l3;
    if(!(ll && ll->next && ll->next->next)){
        printf("Need atleast 3 elements\n");
        return -1;
    }
    l1 = ll;
    l2 = ll->next;
    l3 = ll->next->next;
    while(l3 && l3->next && l3->next->next){
        l1 = l1->next;
        l2 = l2->next->next;
        l3 = l3->next->next->next;
    }
    l3 = l2->next;
    l2->next = NULL;
    l2 = l1->next;  
    l1->next = NULL;
    l1 = ll;
    printf("l1:%d, l2=%d, l3=%d\n", l1->data, l2->data, l3->data);

    return 0;
}




C

Related
urllib.error.HTTPError: HTTP Error 404: Not Found Code Example urllib.error.HTTPError: HTTP Error 404: Not Found Code Example
Uri/Beecrowd problem no - 1149 solution in C Code Example Uri/Beecrowd problem no - 1149 solution in C Code Example
monoalphabetic cipher code in c Code Example monoalphabetic cipher code in c Code Example
Program to input and print array elements in c Code Example Program to input and print array elements in c Code Example
What keyword covers unhandled possibilities? Code Example What keyword covers unhandled possibilities? Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10