向量和链表ADT的区别
有人可以向我解释一下在 ac 编程语言上下文中向量和链接列表 ADT 之间的区别吗?
谢谢。
can someone explain to me the difference between Vector and Linked List ADT in a c programming language context.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
嗯,在 C 中,没有像 C++ std 库那样直接可用的“向量”和“列表”数据类型。但就“抽象数据类型”而言,向量通常被认为表示连续存储,而链表则被认为是由链接在一起的各个单元表示。向量提供快速恒定时间随机访问读写操作,但插入和删除向量元素需要线性时间。列表具有线性查找性能来查找要读取和写入的元素,但给定元素位置,插入和删除的时间恒定。您还可以在恒定时间内将项目添加到列表的开头和结尾(如果 ADT 实现缓存列表中最后一个元素的位置)。
Well, in C, there are no "vector" and "list" data types available to you directly like in C++ std library. But in terms of "abstract data type", a vector is usually considered to represent contiguous storage, and a linked list is considered to be represented by individual cells linked together. Vectors provide fast constant time random-access read and write operations, but inserting and deleting vector elements take linear time. Lists have linear lookup performance to find an element to read and write, but given an element location, have constant time insertion and deletion. You can also add items to the start and to the end of a list in constant time (if the ADT implementation caches the location of the last element in the list).
向量通常被实现为数组的连续内存块。而列表可以分布在内存中,因为每个元素都保存指向一个或多个其他元素的指针(可以是双向链接的)。这为向量提供了访问速度优势,但列出了插入/删除优势。
A vector is often implemented as a contiguous block of memory as an array. Whereas a list can be spread across memory as each element holds pointers to one or more other elements (could be doubly linked). This gives vectors the access speed advantage but lists the insertion/deletion advantage.
基本上,向量驻留在连续的内存中。链表包含指向上一个和下一个结构的指针。矢量对于随机访问来说更快,链表对于增长来说更好。
http://www.codeguru.com/forum/archive/index .php/t-309352.html
Basically, a vector resides in contiguous memory. A linked list contains pointers to the previous and next structures. Vector is faster for random access, the linked list is better for growing.
http://www.codeguru.com/forum/archive/index.php/t-309352.html
矢量是一个动态数组。里面的元素在内存中是相邻的。链表内的元素不相邻。
vector is a dynamic array. the elements inside is adjacent in the memory. The elements inside linked list is not adjacent.