Linked lists, as far as I have seen, are largely implemented using object-oriented ideas. (having an object that holds some information and the address of the next link). How were Linked-lists implemented before the object-oriented paradigm came out? Were they only invented(?) once the OOP was developed?
Linked list have nothing to do with OOP, on fact they predate OOP by quite a bit. Linked list are implemented simply by having a recursive structure, this is in my opinion conceptually easiest to understand in assembly -- you allocate some memory, and the first bytes of that memory serve as a pointer to the next/previous. In assembly you don't have to worry about the "type" and just think of it as another pointer, so the fact that it is recursive is not something you need to think about -- you don't have to think about how something can refer to itself in its definition. |
|||
|
They used, for example in C, struct for simulating a node; and pointers to link the nodes |
|||
|
Well you can always translate OOP code back into non-OOP code (or rather, non OOP-looking code). Actually you can code in an OOP way in any language, but it will not be as convenient as OOP languages.
becomes, in the first step:
or, if you don't have structs:
I don't know if it did look like this, but it very well could. |
|||||
|
What have you seen that is not object-oriented? If the only things you've seen are OO then it is not surprising that the only implementations of simple data structures you've seen are OO.
Linked lists predate OO programming by many decades.
In the 1950's the Lisp programming language was implemented on the IBM 704. The fundamental data structure of Lisp is the cons cell, which is a grouping of two values. The machine word size of the IBM 704 was 36 bits and there were special instructions, CAR and CDR that would extract 15 bit values from a 36 bit word. The value stored in the CAR bits was the head of the list and the value stored in CDR was the tail, so in that way a cons cell could be used as a node in a linked list. For a more detailed discussion of how linked lists were implemented on the IBM 704 in the 1950s, see http://en.wikipedia.org/wiki/CAR_and_CDR. |
|||
|
Linked lists have been around at least as long as OS's and well before HLL's were invented. I can only guess what importance Knuth placed on them, but they were the first concept he discussed in The Art of Computer Programming (Vol 1, Chapter 2). If you really want to know the answer to, "How were Linked-lists implemented before the object-oriented paradigm came out?" I'd suggest purchasing at least volume 1 of TAOCP. The entire work is invaluable. (FWIW - I don't work for Dr. Knuth, or his publisher) jmoreno's answer is accurate. |
||||
|
Badly, mostly. It was pretty common to see sloppy, error-prone code like this:
In many cases the list structure was injected into the class in the list, so you'd get something like:
In short, while anything object orientated could be implemented in a clean, object-orientated fashion, in practice a lot of lists were implemented in an ad hoc and error prone manner in C and similar languages. |
|||||||||||||||||||||
|
How were Linked-lists implemented before the object-oriented paradigm came out?
-- Using raw pointers to actual memory addresses. – Robert Harvey Apr 27 at 0:40