Cock of the walk

What is the origin of the phrase 'Cock of the walk'?

Because a cock living with hens is the boss (he literally ‘rules the roost’), and quickly bullies or pecks any rebels into submission, ‘cock’ has often been used in a figurative sense for ‘leader, head, chief man, ruling spirit, victor, leader in games, fighting, and the like’. You could be cock on your own dunghill, of the school, of the North, of your club, and so on.

The pen in which a fighting cock was kept was called a ‘walk’ (similar to a ‘run’ for hens). So to be ‘cock of the walk’ was to have undisputed supremacy within one’s circle or coterie. (VSD)