top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

If we are using C language to implement the heterogeneous linked list, what pointer type will we use,explain?

+2 votes
posted Sep 9, 2013 by Arvind Singh

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

2 Answers

+2 votes

Don't know what you are trying to do it would be better if you provide more details, check if the following helps you -

typedef struct {
    int type_indicator;
    union {
        float f;
        int i;
        double d;
        void *p;
        char c;
} generic_item;

Above struct that includes a type indicator and a union of the various types that you want to handle will cover almost all the stuff and u can use this build your link list.

answer Sep 9, 2013 by Salil Agrawal
+2 votes

A linked list is known as heterogeneous when every node of linked list can contain different type of information.
A void pointer can point to any type of data either in-built data type or user defined structure . storing such pointer in a void in not a problem. Problem comes at the time of accessing/ reading. since without knowing data structure type how it can be deferenced . so before accessing you should aware about the type. If your program has so many user defined different different data types then defined a

typedef enum { char, integer, float, double, struct type 1, struct type 2 ...etc } datatype;

typedef Struct  heterogeneous_linkedlist
datatype type;
void * nodeInfo.
Struct  heterogeneous_linkedlist *next;
} heterogeneous_node;
answer Sep 9, 2013 by Vimal Kumar Mishra

Useful Links with Similar Problem
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.