Beruflich Dokumente
Kultur Dokumente
3 Implementation
• class Node maintains a (static) list of all objects of class Node in the simulator.
The variable Node::nodehead_ stores the head of the list. The linked list of nodes
is used for centralized routing, for finding satellites to hand off to, and for tracing.
• class Node maintains a list of all (satellite) links on the node. Specifically, the
list is a list of objects of class LinkHead. The variable linklisthead_ stores the
head of the list. The linked list of LinkHeads is used for checking whether or not
to handoff links, and to discover topology adjacencies.
• class Channel maintains a list of all objects of class Phy on the channel. The
head of the list is stored in the variable if_head_. This list is used to determine
the set of interfaces on a channel that should receive a copy of a packet.
Figure 16.4 provides a schematic of how the linked list is organized. Each object in the
list is linked through a ``LINK_ENTRY'' that is a protected member of the class. This
entry contains a pointer to the next item in the list and also a pointer to the address of the
previous ``next'' pointer in the preceding object. Various macros found in list.h can be
used to manipulate the list; the implementation of linked-lists in is similar to the queue
implementation found in some variants of BSD UNIX.
Next: 16.3.2 Node structure Up: 16.3 Implementation Previous: 16.3 Implementation
2000-08-24
Bottom of Form
Stack Overflow
Questions
Tags
Users
Badges
Unanswered
Ask Question
What are some uses for linked lists?
up vote Do linked lists have any practical uses at all. Many computer science books compare
1
them to arrays and say the main advantage is that they are mutable. However, most
down languages provide mutable versions of arrays. So do linked lists have any actual uses
vote in the real world, or are they just part of computer science theory?
favorite
agentbanks217
774210
8 Answers
active oldest votes
Linked lists have many uses. For example, implementing data structures that appear
up vote 2
to the end user to be mutable arrays.
down vote If you are using a programming language that provides implementations of various
accepted collections, many of those collections will be implemented using linked lists. When
programming in those languages, you won't often be implementing a linked list
yourself but it might be wise to understand them so you can understand what tradeoffs
the libraries you use are making. In other words, the set "just part of computer science
theory" contains elements that you just need to know if you are going to write
programs that just work.
link|edit|flag answered Sep 23 '10 at 2:39
mattjames
52827
up vote Yes of course it's useful for many reasons.
2
Anytime for example that you want efficient insertion and deletion from the list. To find
down a place of insertion you have an O(N) search, but to do an insertion if you already have
vote the correct position it is O(1).
Also the concepts you learn from working with linked lists help you learn how to make
tree based data structures and many other data structures.
link|edit|flag answered Sep 23 '10 at 2:20
Brian R. Bondy
68.7k13184320
up vote They're absolutely precious (in both the popular doubly-linked version and the less-
2
popular, but simpler and faster when applicable!, single-linked version). For example,
down inserting (or removing) a new item in a specified "random" spot in a "mutable version of
vote an array" (e.g. a std::vector in C++) is O(N) where N is the number of items in the
array, because all that follow (on average half of them) must be shifted over, and that's
an O(N) operation; in a list, it's O(1), i.e., constant-time, if you already have e.g. the
pointer to the "previous" item. Big-O differences like this are absolutely huge -- the
difference between a real-world usable and scalable program, and a toy, "homework"-
level one!-)
link|edit|flag answered Sep 23 '10 at 2:21
Alex Martelli
159k6164439
2
For representing Polynomials It means in addition/subtraction /multipication.. of two
down polynomials. Eg:p1=2x^2+3x+7 and p2=3x^3+5x+2 p1+p2=3x^3+2x^2+8x+9
vote In Dynamic Memory Management In allocation and releasing memory at runtime. *In
Symbol Tables in Balancing paranthesis
Representing Sparse Matrix
Ref:- http://www.cs.ucf.edu/courses/cop3502h.02/linklist3.pdf
link|edit|flag edited Sep 23 '10 at 2:37 answered Sep 23 '10 at 2:20
Adi_aks
15911
3 Those are some applications, but is representing polynomials really one of the "main"
uses for linked lists? I'd say that there are other way more common uses for them,
such as regular lists and queues. – Emil H Sep 23 '10 at 2:26
up vote A primary advantage to a linked list as opposed to a vector is that random-insertion
1
time is as simple as decoupling a pair of pointers and recoupling them to the new
down object (this is of course, slightly more work for a doubly-linked list). A vector, on the
vote other hand generally reorganizes memory space on insertions, causing it to be
significantly slower. A list is not as efficient, however, at doing things like adding on the
end of the container, due to the necessity to progress all the way through the list.
link|edit|flag answered Sep 23 '10 at 2:23
sleepynate
1,640112
1 Even for singly linked lists, you can keep an end pointer to make it easy to append
elements. – Matthew Flaschen Sep 23 '10 at 2:26
up vote Linked lists are useful because elements can be efficiently spliced and removed in the
1
middle as others noted. However a downside to linked lists are poor locality of
down reference. I prefer not using lists for this reason unless I have an explicit need for the
vote capabilities.
link|edit|flag answered Sep 23 '10 at 2:24
seand
1,05516
up vote An Immutable Linked List is the most trivial example of a Persistent Data Structure,
1
which is why it is the standard (and sometimes even only) data structure in many
down functional languages. Lisp, Scheme, ML, Haskell, Scala, you name it.
vote link|edit|flag answered Sep 23 '10 at 3:22
Jörg W Mittag
53.2k648123
up vote Arrays that grow as needed are always just an illusion, because of the way computer
1
memory works. Under the hood, it's just a continous block of memory that has to be
down reallocated when enough new elements have been added. Likewise if you remove
vote elements from the array, you'll have to allocate a new block of memory, copy the array
and release the previous block to reclaim the unused memory. A linked list allows you
to grow and shrink a list of elements without having to reallocate the rest of the list.
link|edit|flag edited Sep 24 '10 at 3:21 answered Sep 23 '10 at 2:24
Emil H
10.6k2242
Top of Form
Your Answer
Name
o
log in r
Email
shown
required, but never
Home Page
Post Your Answ er
Bottom of Form
Not the answer you're looking for? Browse other questions tagged data-structures
computer-science linked-list or ask your own question.
Hello World!
This is a collaboratively edited question and answer site for professional and enthusiast
programmers. It's 100% free, no registration required.
about » faq »
tagged
data-structures × 3314
computer-science × 774
linked-list × 768