一些简单的算法
//冒泡
-(void)bubbleSort
{
int a[8] = {22, 66, 13, 27, 56, 78, 32, 18};
int iTemp;
for (int i = 0; i < 8; i++)
{
for (int j = 7; j >= i; j--)
{
if (a[j] < a[j-1])
{
iTemp = a[j];
a[j] = a[j-1];
a[j-1] = iTemp;
}
}
NSLog(@"~~BubbleSort~~%d", a[i]);
}
}
//素数
-(void)primeNum
{
int i = 0, j = 0, judge = 1, n = 13;
for (i = 2; i <= n; judge = 1, i++)
{
for (j = 2; j <= i; j++)
{
if (i%j == 0 && i != j)
{
judge = 0;
}
}
if (judge)
{
NSLog(@"~~Prime Number~~%d", i);
}
// else
// {
// NSLog(@"%d ~~Is Not Prime Number~~", i);
// }
}
}