数据结构1——算法
1. 判断是否对称数组
View Code
1 int[] ints = { 1, 2, 3, 4, 4, 3, 2, 1 };
2
3 bool flag =false;
4 for (int i =0; i < ints.Length; i++)
5 {
6 if (ints[i] == ints[ints.Length - i-1])
7 {
8 flag =true;
9 continue;
10 }
11 else
12 {
13 flag =false;
14 break;
15 }
16 }
17 Console.WriteLine(flag.ToString());
18 Console.ReadKey();
2
3 bool flag =false;
4 for (int i =0; i < ints.Length; i++)
5 {
6 if (ints[i] == ints[ints.Length - i-1])
7 {
8 flag =true;
9 continue;
10 }
11 else
12 {
13 flag =false;
14 break;
15 }
16 }
17 Console.WriteLine(flag.ToString());
18 Console.ReadKey();
s
Be the change you want to see in the world.