/**
*@brief 用 C 语言实现异质链表
*@date 2014-10-12
*/
#include<stdio.h>
#include<stdlib.h>
typedef struct Node *PtrToNode;
typedef PtrToNode list;
struct Node
{
void *pData;
int type;//储存数据的类型,1-int,2-float,3-char
PtrToNode next;
};
/**
*@brief 功能:创建一个新的链表
*@param void
*@return list:链表的头
*/
list Create(void)
{
list L;
L=(list)malloc(sizeof(struct Node));
if(NULL==L){
printf("Out of space!");
return NULL;
}
L->next=NULL;
return L;
}
/**
*@brief 功能:插入一个新的节点
*@param P:指向节点的指针 type:输入的数据类型
*@return void
*/
void Insert(list P,int type)
{
PtrToNode temp;
temp=(PtrToNode)malloc(sizeof(struct Node));
if(temp==NULL)
{
printf("Out of space!");
评论0