Linked_List_Example.c
/*
This function removes the node with given index no
First it checks, if the index is first node. If yes 
runs the pop() function adn returns its value.
If no then code iterates to index. In the meantime code
checks if the list end or not.
When the code iterated to the given index, code uses temp
node to remove indexed node.
*/
This function removes the node with given index no
First it checks, if the index is first node. If yes
runs the pop() function adn returns its value.
If no then code iterates to index. In the meantime code
checks if the list end or not.
When the code iterated to the given index, code uses temp
node to remove indexed node.
This function removes the node with given index no First it checks if the index is first node . If yes runs the pop () function adn returns its value . If no then code iterates to index . In the meantime code checks if the list end or not . When the code iterated to the given index code uses temp node to remove indexed node .
int remove_by_index(node_t ** head_ref, int n) {
	int i = 0;
	int retval = -1;
	node_t * current = *head_ref;
	node_t * temp_node = NULL;
	if (n == 0) {
		return pop(head_ref);
	}
	for (i = 0; i < n - 1; i++) {
		if (current->next == NULL) {
			return -1;
		}
		current = current->next;
	}
	temp_node = current->next;
	retval = temp_node->val;
	current->next = temp_node->next;
	free(temp_node);
	return retval;
}
int remove_by_index ( node_t * * head_ref , int n ) { int i = 0 ; int retval = -1 ; node_t * current = * head_ref ; node_t * temp_node = NULL ; if ( n == 0 ) { return pop ( head_ref ) ; } for ( i = 0 ; i < n - 1 ; i ++ ) { if ( current -> next == NULL ) { return -1 ; } current = current -> next ; } temp_node = current -> next ; retval = temp_node -> val ; current -> next = temp_node -> next ; free ( temp_node ) ; return retval ; }
This function removes the node with given index no
First it checks, if the index is first node.
This function removes the node with given index no First it checks if the index is first node .