是否有可能有不同的数据类型的链接列表? [英] Is it possible to have a linked list of different data types?
本文介绍了是否有可能有不同的数据类型的链接列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是另一个面试问题。
我们能有不同的数据类型的链表,即在链表的每个元素可以有不同的结构或联合的元素?如果有可能可以请您用一个例子解释一下吗?
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;
};
使用结构节点创建链表。类型决定什么是数据的数据类型。
Use struct node to create linked list. type decides what is the datatype of the data.
戒T,班加罗尔
这篇关于是否有可能有不同的数据类型的链接列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文