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
def search ( arr , n , x ) : NEW_LINE INDENT res = - 1 NEW_LINE for i in range ( 0 , n , 1 ) : NEW_LINE INDENT if ( x == arr [ i ] ) : NEW_LINE INDENT res = i NEW_LINE DEDENT DEDENT if ( res == - 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT temp = arr [ res ] NEW_LINE i = res NEW_LINE while ( i > 0 ) : NEW_LINE INDENT arr [ i ] = arr [ i - 1 ] NEW_LINE i -= 1 NEW_LINE DEDENT arr [ 0 ] = temp NEW_LINE return True NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 12 , 25 , 36 , 85 , 98 , 75 , 89 , 15 , 63 , 66 , 64 , 74 , 27 , 83 , 97 ] NEW_LINE q = [ 63 , 63 , 86 , 63 , 78 ] NEW_LINE n = len ( arr ) NEW_LINE m = len ( q ) NEW_LINE for i in range ( 0 , m , 1 ) : NEW_LINE INDENT if ( search ( arr , n , q [ i ] ) ) : NEW_LINE INDENT print ( " Yes " , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT