1:线性表定义:零个或多个数据元素的有限序列
2:
线性表元素个数n定义为线性表的长度,n = 0称为空表,i 为数据元素ai在线性表中的位序。
3:满足线性表的条件:(1):有序,有限
(2):第一个元素无前驱,最后一个元素无后继
(3):数据类型相同
(4):元素之间首位相连
4:线性表两种存储结构:顺序存储结构和链式存储结构
5:顺序存储结构定义:指的是用一段地址连续的存储单元依次存储线性表的数据元素。
6:数据长度和线性表长度的区别:数组长度是存放线性表的存储空间的长度,一般不变。线性表长度是线性表中数据元素的个数,会随着插入和删除而改变。
7:插入操作:
public void Insert(string[] str,int index, string item) { Array.Resize(ref str, str.Length + 1);//将一维数组的元素数更改为指定的新大小。 int length = str.Length; if (index < 0 || index > length) throw new Exception("Location exception"); if (index < length)//不是在末尾插入 { for (int i = str.Length - 1; i > index - 1; i--) { str[i] = str[i - 1 ]; } } str[index - 1] = item; }
8:删除操作:
public void Delete(string[] str, int index) { int length = str.Length; if (index <= 0 || index > length) throw new Exception("Location exception"); if (index < length)//不是在末尾删除 { for (int i = index - 1; i < str.Length - 1; i++) { str[i] = str[i + 1]; } } Array.Resize(ref str, str.Length - 1); }
9:优缺点:
优点: (1):无须为表示表中之间的逻辑关系而增加额外的存储空间
(2):可以快速的读取表中的任意位置的元素
缺点:(1):插入和删除操作需要移动大量元素
(2):当线性表长度变化较大时,难以确定存储空间的容量
(3):造成存储空间的"碎片"。.