human
Print elements of an array according to the order defined by another array | set 2 | Function to print an array according to the order defined by another array.
Declaring map and iterator.
Store the frequency of each number of a1 [ ] int the map.
Traverse through a2 [ ].
Check whether number is present in map or not.
Print that number that many times of its frequency.
Print those numbers that are not present in a2 [ ].
Driver code"
Solution in Python:
assistant
#Here is code to print elements of an array according to the order defined by another array and the other steps required.
 def print_in_order ( a1 , a2 , n , m ) :
	mp = dict . fromkeys ( a1 , 0 ) ;
	for i in range ( n ) :
		mp [ a1 [ i ] ] += 1 ;
	for i in range ( m ) :
		if a2 [ i ] in mp . keys ( ) :
			for j in range ( mp [ a2 [ i ] ] ) :
				print ( a2 [ i ] , end = " ▁ " ) ;
			del ( mp [ a2 [ i ] ] ) ;
	for key , value in mp . items ( ) :
		for j in range ( value ) :
			print ( key , end = " ▁ " ) ;
	print ( ) ;
if __name__ == " _ _ main _ _ " :
	a1 = [ 2 , 1 , 2 , 5 , 7 , 1 , 9 , 3 , 6 , 8 , 8 ] ;
	a2 = [ 2 , 1 , 8 , 3 ] ;
	n = len ( a1 ) ;
	m = len ( a2 ) ;
	print_in_order ( a1 , a2 , n , m ) ;