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. |
|||
|
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 13 hours ago