Algorithm For Sorting Shapes By Attributes