14

数据存储结构

 3 years ago
source link: http://www.cnblogs.com/nadou/p/13972392.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

一、数据存储结构

数据存储的常用结构有:堆栈、队列、数组、链表。

1.1 堆栈

① 先进后出

② 压栈:存元素

③ 弹栈:取元素

QfiUNbn.png!mobile

1.2 队列

① 先进先出

② 出队

③ 入队

eye6FzI.jpg!mobile

1.3 数组

查找元素快 :通过索引,可以快速访问指定位置的元素

增删元素慢

:open_hands: 指定索引位置增加元素 :需要创建一个新数组,将指定新元素存储在指定索引位置,再把原数组元素根据索引,复制到新数组对应索引的位置。

:open_hands: 指定索引位置删除元素 :需要创建一个新数组,把原数组元素根据索引,复制到新数组对应索引的位置,原数组中指定索引位置元素不复制到新数组中。

qiUZRfA.jpg!mobile

1.4 链表

查找元素慢 :想查找某个元素,需要通过连接的节点,依次向后查找指定元素

增删元素快

:open_hands: 增加元素:操作如左图,只需要修改连接下个元素的地址即可。

:open_hands: 删除元素:操作如右图,只需要修改连接下个元素的地址即可。

BRNRJ3v.jpg!mobile


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK