c/linkedlists/single_ll.c
SListNode *insert_slist(SListNode *l, int i) {
    if (l == NULL) {
        if ((l = malloc(sizeof (SListNode))) == NULL) {
            return NULL;
        } else {
            l->elem = i;
            l->next = NULL;   
            return l;
        }   
    
    } else {
        SListNode *res = insert_slist(NULL, i);
        SListNode *node = l;
        while (node->next != NULL) {
            node = node->next;
        }
        if (res == NULL) {
            return NULL;
        } else {
            node->next = res;
            return l;
       }
    }
}
// Insert element into linked list,
// creates a new list if SListNode is NULL.
// Returns root of list if successful, NULL otherwise
Insert element into linked list,
creates a new list if SListNode is NULL.
Returns root of list if successful, NULL otherwise
Insert element into linked list creates a new list if SListNode is NULL . Returns root of list if successful NULL otherwise
SListNode *insert_slist(SListNode *l, int i) {
    if (l == NULL) {
        if ((l = malloc(sizeof (SListNode))) == NULL) {
            return NULL;
        } else {
            l->elem = i;
            l->next = NULL;   
            return l;
        }   
    } else {
        SListNode *res = insert_slist(NULL, i);
        SListNode *node = l;
        while (node->next != NULL) {
            node = node->next;
        }
        if (res == NULL) {
            return NULL;
        } else {
            node->next = res;
            return l;
       }
    }
}
SListNode * insert_slist ( SListNode * l , int i ) { if ( l == NULL ) { if ( ( l = malloc ( sizeof ( SListNode ) ) ) == NULL ) { return NULL ; } else { l -> elem = i ; l -> next = NULL ; return l ; } } else { SListNode * res = insert_slist ( NULL , i ) ; SListNode * node = l ; while ( node -> next != NULL ) { node = node -> next ; } if ( res == NULL ) { return NULL ; } else { node -> next = res ; return l ; } } }
Insert element into linked list,
creates a new list if SListNode is NULL.
Insert element into linked list creates a new list if SListNode is NULL .