Partition Function: Chooses the last element as the pivot. Rearranges the array so that elements less than the pivot are on the left, and greater on the right. Returns the partitioning index.