Search
 
SCRIPT & CODE EXAMPLE
 

C

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
");
        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
", l1->data, l2->data, l3->data);

    return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: insertNode 
C :: Combine two sentences into one langage c 
C :: bool print variable in c 
C :: c program to pass a single element in an funtional array 
C :: hgggggggggggggggg 
C :: how to make C program blink on screen 
C :: libreoffice reference cell in different sheet with sheet name with space 
C :: error: ‘_Atomic’ does not name a type 
C :: What keyword covers unhandled possibilities? 
C :: command line arguments to copy paste in c 
C :: python project script run 
C :: Writing tests for API requests 
C :: diiferent between * and & in c 
C :: 50 north main 07522 
C :: c joystick arduino 
C :: Sum of upper & lower triangles elements 
C :: wpdb add temporary while drop table 
C :: Calculate the area of a circle and modify the same program to calculate the volume of a cylinder given its radius and height. 
C :: how to compress image in c 
C :: gotoxy not working in dev c++ 
C :: C temporary files 
C :: vs code turn off formatter 
C :: c while loop 
Dart :: flutter listtile shape border 
Dart :: flutter disbal PageView swipe 
Dart :: flutter appbar width 
Dart :: flutter singleton 
Dart :: flutter showsnackbar 
Dart :: flutter listtile minverticalpadding 
Dart :: flutter string contains 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =