It seems like they both do the same thing in the same way: Lazy operations in a specific but not-necessarily-indexed order, and cannot necessarily backtrack.
preguntado el 24 de agosto de 12 a las 06:08
Linked list is a specific way of representing sequences of data elements in memory, where each element is paired with a pointer of sorts to the next element in the sequence. Linked lists let you perform a range of operations on their subsequences: you can cut out or insert entire chains of elements, or delete elements from the middle at a very low cost.
Streams, on the other hand, are abstractions for accessing data in sequential order, without any specific requirements to their representation in memory. You can use a linked list to implement a stream, but you could also use another data structure for that, such as a plain array or a circular array buffer.
I think this is a little like trying to compare apples and oranges.
A linked list is a data structure where each node points to another node. They're a useful structure as inserting and removing items from a linked list is just a matter of re-pointing a node, rather than with an array where you need to do allot more shuffling. See http://en.wikipedia.org/wiki/Linked_list para obtener más información.
A stream is an abstracted object used to represent a series of bytes. In most frameworks (Java, .NET etc) there are several concrete implementations of steams (memory stream, file stream etc) used to read the byte array from the relevant source (memory, file etc).
A linked list is a data structure where each element has a pointer to the next one, and possibly the same in the other direction. Circular linked lists even have a pointer from the last to the first element and vice versa. Those pointers (or references in languages that don't have pointers) are what defines the data structure. They imply a certain mode of operation, they don't force that, though. The
LinkedList class in Java, for example, can be used like an array, although it won't be very effective then. It also can be used as (double-ended) queue or stack, depending on which functions you call.
A stream, on the other hand, is not defined as a data structure, but as a source or sink of elements. These elements could be bytes or characters, if you think of file streams, socket streams or reader/writer classes that wrap streams. The elements provided by a stream could also be more complex, e.g. tokens for a parser. In that case the stream likely uses some kind of queue internally, which could be implemented using a linked list or some array construction.
Just make sure to understand these two things are defined on different layers of abstraction. The linked list is defined on how it works internally, while the stream is defined on how it works externally.
There is a common abstraction between a read-only singly-linked list and an input stream, which C++ formalises as
InputIterator: you can read a value and you can move forwards. In many stream APIs you have to do both simultaneously, but given that API it's fairly easy to see how to separate them out with a wrapper that caches one value: C++ calls this class
However, a singly-linked list has a property that a stream does not always have, which C++ formalises as
ForwardIterator: you can copy the current position, move the copia forward, but still read the value at the location of the original. A generalized stream cannot do this, because the underlying I/O only has one "current position". With a linked list you can have multiple pointers to different nodes in the list, with no troubles.
Some streams can be marked and reset, rewound, seeked (sought?) etc, adding facilities that are somewhat like a C++ ForwardIterator, or even RandomAccessIterator.
I use C++ as an example not because it's particularly important, but because the C++ concept of an iterator is designed in part to provide an abstraction common to data structures and streams. Not all languages have such a common abstraction, but for another example in Python you can write
for x in y: if
y is a container data structure or if
y is a file-like object, or in general if
y is "iterable".