Sie sind auf Seite 1von 6

Next: 16.3.2 Node structure Up: 16.3 Implementation Previous: 16.

3 Implementation

16.3.1 Use of linked lists

Figure: Linked list implementation in .


linked-list

There are a number of linked lists used heavily in the 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

×Welcome to Q&A for professional and enthusiast programmers —


check out the FAQ!
Stack Exchange
log in | careers | chat | meta | about | faq
Top of Form

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

data-structures computer-science linked-list


link|edit|flag asked Sep 23 '10 at 2:16

agentbanks217
774210

100% accept rate

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

up vote The main Applications of Linked Lists are

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

asked 7 months ago


viewed 450 times
active 7 months ago

Junior TSG Application Engineer


Two Sigma Investments
New York, NY
Senior Software Engineer (Animation) - Based in Singapore
Autodesk Asia Pte
Singapore, Singapore
Business Analytics Manager
TripAdvisor
Singapore, Singapore
Software Engineer in Test (Ovi Maps)
Nokia
Berlin, Germany
LAMP Developer/Systems Admin (Work From Home)
WL Online Marketing
Faridabad, Haryana, India;...
Software QA Engineer (m/f)
NumberFour AG
Berlin, Germany
view more jobs
Related
Splitting a linked list
What are real world examples of when Linked Lists should be used?
Single linked list
Sorting two linked lists according to memory location
Do you use linked lists, doubly linked lists and so on, in business programming?
How to write a function that gets a linked list of any node type and frees the memory used by it?
Most optimal way to find the sum of 2 numbers represented as linked lists
Doubly Linked List in a Purely Functional Programming Language
Advantages of linked lists over binary trees?
Why are linked lists almost always used with separate chaining?
Different Types of Linked Lists!
Under what circumstances are linked lists useful?
C++ stl collections or linked lists
What is a Cursor Linked List? [C++]
What's the right way to do mutable data structures (e.g., skip lists, splay trees) in F#?
Item in multiple lists
What will be the complexity of the operation to remove an element from the end of the singly linked list ?
Linked list in Pascal
What is the smartest data structure to use when doing several lookups and insertions, but no deletes?
How to add node at some specific index in a linked list?
What is the point of PHP's SplDoublyLinkedList class, and more importantly, Linked Lists in general?
Linked Lists, Assigning char array [C]
Doubly Linked Lists Implementation
can anybody help me to understand how copying a linked list to other list is work ?
Linked List From Text File
question feed
about | faq | blog | chat | data | podcast | legal | advertising info | contact us | feedback always
welcome
■ stackoverflow.com ■ api/apps ■ careers ■ serverfault.com ■ superuser.com ■ meta
■ area 51 ■ webapps ■ gaming ■ ubuntu ■ webmasters ■ cooking ■ game development
■ math ■ photography ■ stats ■ tex ■ english ■ theoretical cs ■ programmers ■ unix
■ apple ■ wordpress ■ physics ■ home improvement ■ gis ■ electronics ■ android
rev 2011.5.7.2
site design / logo © 2011 stack exchange inc; user contributions licensed under cc-wiki with attribution
required

Das könnte Ihnen auch gefallen