Is it possible to have a linked list of different data types?

后端 未结 11 2108
独厮守ぢ
独厮守ぢ 2020-12-13 22:22

This is just another interview question.

Can we have a linked list of different data types, i.e. each element in a linked list can have different structure or union

11条回答
  •  生来不讨喜
    2020-12-13 23:07

    Actually, you don't have to put the pointer first in the structure, you can put it anywhere and then find the beginning fo the struct with a containerof() macro. The linux kernel does this with its linked lists.

    http://isis.poly.edu/kulesh/stuff/src/klist/

提交回复
热议问题