是否可以有不同数据类型的链表?

编程入门 行业动态 更新时间:2024-10-25 22:33:44
本文介绍了是否可以有不同数据类型的链表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这只是另一个面试问题.

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

更多推荐

是否可以有不同数据类型的链表?

本文发布于:2023-10-25 14:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1527212.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据类型   链表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!