Write a function that adds an element of type (char *) to a hash table in which collisions are resolved by applying the hash coalesced with separated zones.


Difficulty level
Video recording
This exercise is mostly suitable for students
int add_coalesced(hashtable T, int m, element e, int p)
{	int r, v = hash_function(e) ; 
	if (empty(T,v)){ 
		strcpy(T[v].data,e);
		T[v].link = -1 ;
		return 1 ;
	}

	while (T[v].link != -1 && strcmp(T[v]. data , e))
		v = T[v].link ;
	if(strcmp(T[v].data,e)==0) return 0;
	 r = m-1; 
	while (r >= p && !empty(T,r)) r--;
	if (r < p) return 0 ;
	strcpy(T[r].data,e); 
	T[r].link = -1 ;
	T[v].link = r ;
	return 1 ;
} 

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Removing a sequence of 3 characters from a string