human
Reallocation of elements based on Locality of Reference | A function to perform sequential search ..
Linearly search the element.
If not found.
Shift elements before one position.
Driver Code"
Solution in Python:
 Can you provide a code to reallocation of elements based on Locality of Reference and the other steps required?
assistant
#Here is code to reallocation of elements based on Locality of Reference and the other steps required.
 def search ( arr , n , x ) :
	res = - 1
	for i in range ( 0 , n , 1 ) :
		if ( x == arr [ i ] ) :
			res = i
	if ( res == - 1 ) :
		return False
	temp = arr [ res ]
	i = res
	while ( i > 0 ) :
		arr [ i ] = arr [ i - 1 ]
		i -= 1
	arr [ 0 ] = temp
	return True
if __name__ == ' _ _ main _ _ ' :
	arr = [ 12 , 25 , 36 , 85 , 98 , 75 , 89 , 15 , 63 , 66 , 64 , 74 , 27 , 83 , 97 ]
	q = [ 63 , 63 , 86 , 63 , 78 ]
	n = len ( arr )
	m = len ( q )
	for i in range ( 0 , m , 1 ) :
		if ( search ( arr , n , q [ i ] ) ) :
			print ( " Yes " , end = " ▁ " )
		else :
			print ( " No " , end = " ▁ " )