exercises/ex13/list_errors_soln.c
int insert_by_index(Node **head, int val, int index) {
    int i;
    Node *node = *head;

    if (index == 0) {
        push(head, val);
        return 0;
    }

    for (i=0; i<index-1; i++) {
        if (node == NULL) return -1;
        node = node->next;
    }
    if (node == NULL) return -1;
    node->next = make_node(val, node->next);
    return 0;
}
/* Adds a new element to the list before the indexed element.

Index 0 adds an element to the beginning.
Index 1 adds an element between the first and second elements.

Returns 0 if successful, -1 if the index is out of range.
*/
Adds a new element to the list before the indexed element.
Index 0 adds an element to the beginning.
Index 1 adds an element between the first and second elements.

Returns 0 if successful, -1 if the index is out of range.
Adds a new element to the list before the indexed element . Index 0 adds an element to the beginning . Index 1 adds an element between the first and second elements . Returns 0 if successful - 1 if the index is out of range .
int insert_by_index(Node **head, int val, int index) {
    int i;
    Node *node = *head;
    if (index == 0) {
        push(head, val);
        return 0;
    }
    for (i=0; i<index-1; i++) {
        if (node == NULL) return -1;
        node = node->next;
    }
    if (node == NULL) return -1;
    node->next = make_node(val, node->next);
    return 0;
}
int insert_by_index ( Node * * head , int val , int index ) { int i ; Node * node = * head ; if ( index == 0 ) { push ( head , val ) ; return 0 ; } for ( i = 0 ; i < index - 1 ; i ++ ) { if ( node == NULL ) return -1 ; node = node -> next ; } if ( node == NULL ) return -1 ; node -> next = make_node ( val , node -> next ) ; return 0 ; }
Adds a new element to the list before the indexed element.
Adds a new element to the list before the indexed element .