本文介绍了是否可以有不同数据类型的链表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这只是另一个面试问题.
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 elements? If it's possible can you please explain with an example?
推荐答案使用 union 创建数据类型
Use union to create the datatype
union u_tag{ char ch; int d; double dl; }; struct node { char type; union u_tag u; struct node *next; };使用struct node创建链表.type 决定数据的数据类型.
Use struct node to create linked list. type decides what is the datatype of the data.
Harsha T,班加罗尔
Harsha T, Bangalore
更多推荐
是否可以有不同数据类型的链表?
发布评论