1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| namespace 交叉数组的遍历 { internal class Program { static void Main(string[] args) { int[][] arr; arr = new int[3][]; arr[0] = new int[2] { 1, 2}; arr[1] = new int[3] { 2, 3 ,4 }; arr[2] = new int[4] { 2, 3, 4, 5 }; for (int i = 0; i < arr.GetLength(0); i++) { for (int j = 0; j < arr[i].Length; j++) { Console.Write(arr[i][j]); Console.Write(' '); } Console.WriteLine(); } Console.WriteLine("Hello, World!"); } } }
|
本周作业:完成数组删除函数的编写
刚刚回答了个问题(就是下面这份代码的编写和讲解),拿了一些平时分,感觉还是不错的。不过感觉自己的语言表达能力还是有点不足,未来还得加强。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| namespace 插入函数 { internal class Program {
static int[] AddArrayElement(int[] arrayBom, int ser, int value) { int length = arrayBom.Length + 1; int[] answer = new int[length]; if (ser >= length) ser = length - 1; int num = 0; for (int i = 0; i < length; i++) { if (i == ser) answer[i] = value; else { answer[i] = arrayBom[num++]; } } return answer; } static void Main(string[] args) { int[] a = new int[8];
int id, val; Console.WriteLine("请输入插入的位置"); id = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("请输入插入的值"); val = Convert.ToInt32(Console.ReadLine()); a[0] = 1; a[1] = 2; a[2] = 3; a[3] = 4; a = AddArrayElement(a, id, val);
for (int i = 0; i < a.Length; i++) { Console.WriteLine(a[i]); } Console.WriteLine("Hello, World!"); } } }
|
完成作业后我会把程序放到这篇文章最后,如果你看到这篇文章时哦还没有更新,记得提醒我,谢谢咕咕咕
哦对,还有一个作业,将优化后的选择排序代码改为降序排序,别忘了。