Searching element in the stack
function stack_search ( stack , element ) { var pos = - 1 , co = 0 ; while ( stack . length > 0 ) { co ++ ; if ( stack [ stack . length - 1 ] == element ) { pos = co ; break ; } stack . pop ( ) ; } if ( pos == - 1 ) document . write ( " " + " " ) ; else document . write ( " " + pos + " " ) ; }