if(springs[i].ij > springs[i+1].ij) { ClothSpring *ts = &springs[i]; springs[i] = springs[i+1]; springs[i+1] = *ts; changed = 1; }