是否可以有不同数据类型的链表? [英] Is it possible to have a linked list of different data types?
本文介绍了是否可以有不同数据类型的链表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这只是另一个面试问题.
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
这篇关于是否可以有不同数据类型的链表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文