#include <stdio.h>
#include <malloc.h>
#include <string.h>
typedef int bool;
enum { false, true };
typedef enum {
int_t =0,
float_t =1,
char_t =2
} datatype;
struct node
{
void *info;
datatype d;
struct node *next;
} *ptr1,*newnode,*start;
void insert_at_last(struct node **bt,void *data,int n)
{
struct node *temp = *bt;
ptr1=(*bt);
switch(n)
{
case int_t:
newnode= (struct node *)malloc(sizeof(struct node));
newnode->d=int_t;
newnode->info = malloc(sizeof(int));
memcpy(newnode->info,data,sizeof(int));
break;
case float_t:
newnode= (struct node *)malloc(sizeof(struct node));
newnode->d=float_t;
newnode->info = malloc(sizeof(float));
memcpy(newnode->info,data,sizeof(float));
break;
case char_t:
newnode= (struct node *)malloc(sizeof(struct node));
newnode->d=char_t;
newnode->info = malloc(sizeof(char));
memcpy(newnode->info,data,sizeof(char));
break;
default:
break;
}
newnode->next=NULL;
if((*bt)==NULL)
*bt=newnode;
else
{
while(temp->next!=NULL)
temp = temp->next;
temp->next=newnode;
}
}
void display(struct node *ptr)
{
if(ptr==NULL)
printf("List Empty\n");
else
{
while(ptr!=NULL)
{
if(ptr->d==int_t)
printf("%d :",*(int*)ptr->info);
if(ptr->d==float_t)
printf("%f :",*(float*)ptr->info);
if(ptr->d==char_t)
printf("%c :",*(char*)ptr->info);
ptr=ptr->next;
}
}
printf("\n");
}
int main()
{
int toExit = 0;
int i,j;
datatype choice;
char c;
float f;
start=NULL;
for(j=0;j<5;j++)
{
printf("Enter which type u want to enter : 13 to exit\n");
scanf("%d",&choice);
switch(choice)
{
case int_t:
printf("Enter int data\n");
scanf("%d",&i);
insert_at_last(&start,&i,int_t);
break;
case float_t:
printf("Enter float data\n");
scanf("%f",&f);
insert_at_last(&start,&f,float_t);
break;
case char_t:
printf("Enter char data\n");
getchar();
scanf("%c",&c);
insert_at_last(&start,&c,char_t);
break;
default:
toExit = 1;
break;
}
if (toExit)
{
break;
}
}
display(start);
}