单链表的优缺点_链表的优缺点

单链表的优缺点

Here you will learn about advantages and disadvantages of linked list.

在这里,您将了解链表的优缺点。

It is a data structure in which elements are linked using pointers. A node represents an element in linked list which have some data and a pointer pointing to next node. Its structure looks like as shown in below image.

它是一种数据结构,其中的元素使用指针链接。 一个节点代表链表中的一个元素,该元素具有一些数据和一个指向下一个节点的指针。 其结构如下图所示。

Advantages and Disadvantages of Linked List

There are various merits and demerits of linked list that I have shared below.

我在下面分享了链表的各种优缺点。

链表的优缺点 (Advantages and Disadvantages of Linked List)

链表的优点 (Advantages of Linked List)

Dynamic Data Structure

动态数据结构

Linked list is a dynamic data structure so it can grow and shrink at runtime by allocating and deallocating memeory. So there is no need to give initial size of linked list.

链表是一个动态数据结构,因此它可以在运行时通过分配和取消分配内存来增长和收缩。 因此,无需给出链表的初始大小。

Insertion and Deletion

插入和删除

Insertion and deletion of nodes are really easier. Unlike array here we don’t have to shift elements after insertion or deletion of an element. In linked list we just have to update the address present in next pointer of a node.

节点的插入和删除确实非常容易。 与数组不同,在插入或删除元素后,我们不必移动元素。 在链表中,我们只需要更新节点的下一个指针中存在的地址即可。

No Memory Wastage

没有记忆浪费

As size of linked list can increase or decrease at run time so there is no memory wastage. In case of array there is lot of memory wastage, like if we declare an array of size 10 and store only 6 elements in it then space of 4 elements are wasted. There is no such problem in linked list as memory is allocated only when required.

由于链表的大小可以在运行时增加或减小,因此不会浪费内存。 在数组的情况下,会浪费大量内存,例如,如果我们声明一个大小为10的数组并在其中仅存储6个元素,那么就会浪费4个元素的空间。 链表中没有这种问题,因为仅在需要时才分配内存。

Implementation

实作

Data structures such as stack and queues can be easily implemented using linked list.

使用链接列表可以轻松实现诸如堆栈和队列之类的数据结构。

链表的缺点 (Disadvantages of Linked List)

Memory Usage

内存使用情况

More memory is required to store elements in linked list as compared to array. Because in linked list each node contains a pointer and it requires extra memory for itself.

与数组相比,在链表中存储元素需要更多的内存。 因为在链表中,每个节点都包含一个指针,并且它本身需要额外的内存。

Traversal

遍历

Elements or nodes traversal is difficult in linked list. We can not randomly access any element as we do in array by index. For example if we want to access a node at position n then we have to traverse all the nodes before it. So, time required to access a node is large.

在链表中很难遍历元素或节点。 我们不能像按索引在数组中那样随机访问任何元素。 例如,如果我们要访问位置n处的节点,则必须遍历它之前的所有节点。 因此,访问节点所需的时间很大。

Reverse Traversing

反向遍历

In linked list reverse traversing is really difficult. In case of doubly linked list its easier but extra memory is required for back pointer hence wastage of memory.

在链表中,反向遍历确实很困难。 在双链表的情况下,它比较容易,但是向后指针需要额外的内存,因此浪费了内存。

影片教学 (Video Tutorial)

翻译自: https://www.thecrazyprogrammer.com/2016/11/advantages-disadvantages-linked-list.html

单链表的优缺点

  • 8
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值