冒泡法
private void show(int[] obj)
...{
int i = 0;
int j = 0;
int tmp = 0;
for (i = 0; i < obj.Length; i++)
...{
for (j = 0; j < obj.Length - i - 1; j++)
...{
if (obj[j] >obj[j + 1])
...{
tmp = obj[j];
obj[j] = obj[j + 1];
obj[j + 1] = tmp;
}
}
}
}
protected void Button2_Click(object sender, EventArgs e)
...{
int[] obj =...{ 100, 200, 5, 800, 940, 75, 851, 456,11111,0,1 };
show(obj);
for (int k = 0; k < obj.Length; k++)
...{
Response.Write(obj[k].ToString() + "<br/>");
}
}
斐波那契
1
protected void Button3_Click(object sender, EventArgs e)
...{
int[] fib = ...{1,1,1,1,1,1,1,1,1,1};
int i;
for(i=2;i<fib.Length;i++) 
...{
fib[i ] = fib[i-1]+fib[i-2];
}
for(i=0;i<fib.Length;i++) 
...{
Response.Write( i+"=="+ fib[i]+"<br/>");
}
}
2
protected void Button4_Click(object sender, EventArgs e)
...{
Response.Write(Fib(6));
}
public int Fib(int n)
...{
if (n <= 0) throw new OverflowException();
if (n >= 3)
return Fib(n - 1) + Fib(n - 2);
else
return 1;
}
4291

被折叠的 条评论
为什么被折叠?



