Node * List_insert(Node * head, int v) { printf("insert %d\n", v); Node * p = Node_construct(v); p -> next = head; return p; /* insert at the beginning */ }
Node * List_insert3(Node *front, int val) { if(front == NULL) { return Node_construct(val); } Node * p = front; while ((p->next)!= NULL) { p = p->next; } p -> next = Node_construct(val); return front; //IF RETURN P }
Node * List_insert2(Node * front, int val) { if(front == NULL) { return Node_construct(val); } front -> next = List_insert2(front->next, val); return front; // if front is null retun new node, or else it returns front. // front->next = front->next }
Node * List_insertSort(Node * front, int val) { if(front == NULL) { return Node_construct(val); } if((front->data) > val) { Node * n = Node_constrcut(val); n-> next = front; return n; } //can use a while loop front->next = List_insertSort(front->next, val); //when reached, the return n in the //if loop will make the link to the previous val return front; }
Node * List_insert(Node * front, int val) { Node * n = Node_construct(val); n -> next = front; return n; }