//
//  arrayBSorter.m
//  fontry
//
//  Created by Matteo Rattotti on 10/12/06.
//  Copyright 2006 __MyCompanyName__. All rights reserved.
//

#import "arrayBSorter.h"


@implementation arrayBSorter
- (NSMutableArray *) BSort:(NSMutableArray *)array size:(unsigned) arraylen sortBy:(bool) WorH{
	bool has_swapped = 1;
	while(has_swapped){
		has_swapped = 0;
		int i = 0;
		for (i; i < arraylen -1; ++i) {
			int index = i;
			NSSize len1 = [[array objectAtIndex:index] size];
			NSSize len2 = [[array objectAtIndex:index +1] size];
			float one,two;
			if(WorH == 0){
				one = len1.width;
				two = len2.width;
			}
			else{
				one = len1.height;
				two = len2.height;
			}
			if(one > two){
				[array exchangeObjectAtIndex:index withObjectAtIndex:index +1];
				has_swapped = 1;
			}
		}
	}
	
	return array;
}

@end
