Function to display the resultamt stack
static void display ( Stack < Integer > res ) { int N = res . size ( ) ; String s = " " ; while ( ! res . isEmpty ( ) ) { s = String . valueOf ( res . peek ( ) ) + s ; res . pop ( ) ; } System . out . print ( s + "NEW_LINE"); }