大话数据结构三:线性表的链式存储结构(静态链表)
1. 静态链表:用数组描述的链表叫静态链表,通常为方便数据插入,我们会把数组建的大一些。
2. 数组元素(node):由两个数据域组成(data,cursor)。数据域data用来存放数据元素,也就是通常我们要处理的数据;而cursor相当于单链表中的指针,存放该元素的后继在数组中的下标
3. java实现静态链表:
// 测试类public class Main {public static void main(String[] args) {int arr[] = { 1, 3, 4, 5, 6 };StaticLinkedList list = new StaticLinkedList(arr);System.out.print("初始化:\n");list.display();System.out.print("\n在角标为1的位置插入2后:\n");list.insert(1, 2);list.display();System.out.print("\n删除角标为5的结点后:\n");list.delete(5);list.display();}}4. 静态链表的优越点:
优点:在插入和删除操作时,不需要移动元素,从而改进了在顺序存储结构中插入和删除操作需要移动大量元素的缺点。
缺点:没有解决连续存储分配带来表长难以确定的问题。
5. 总的来说,静态链表其实是为了给没有指针的高级语言设计的一种实现单链表的方法,一般很少用。