Pergunta de entrevista da empresa Colgate-Palmolive

On a piece of paper, write a function for bubble sort. No pseudo code, and please explain why this works.