1) Olimar plucks 4 Pikmin that come out in the order of Yellow > Purple > Red > White
2a) If Olimar hasn't whistled yet, or if his last whistle put Purple in front, then that means that it's Red's turn to go to the front of the line and the whistle will reorganize his Pikmin like this: Red > Yellow > White > Purple.
2b) If Olimar has whistled once, then that means that it's Yellow's turn to take the lead. Which would reorganize step 1's list to be: Yellow > White > Purple > Red.
This is important to note, because good organization through Whistle and your Pikmin attacks can lead to you getting the Pikmin you want to the front faster.
As an example of good Whistle organization, let's say your lineup is Red > Blue > Purple > Purple, and it's Blue's turn next Whistle.
Whistle once to make the order Blue > Purple > Purple > Red.
Next use ANY Pikmin attack to change the order Purple > Purple > Red > Blue.
Now you can use both of your Purple Pikmin, then Whistle ONCE and both Purple Pikmin will be the next in line again. This is because the Whistle saves whatever the last color you were on, regardless of how you use your Pikmin. It also saves whatever color is next in line after Olimar uses a stock, so if you were to lose a stock using the previous example (with Red being next in line), and you have a line up of Yellow > Yellow > Red > White and you whistle, Red will jump to the front of the line because Purple was the last Pikmin to be called to the front with Whistle.