Hey guys, I defined a stack data structure a couple days ago,
Code:
struct linknode {
elemtype data;
struct linknode *
last;
};
struct linkstack {
struct linknode *top;
};
typedef struct linknode *lnode;
typedef struct linkstack *lstack;
;
And I've also defined some functions for these two.
Look I didnt assign what elemtype is in my structure. Now I have to use two stack and their elemtype are different(one is double, one is char)!!!
The problem is I dont wanna re-write two kind of stack, and replace all elemtype with char(or double). To do this, I'll have to implement functions for each one.
Is there a way out?
Some guys says I should use (void *) for elemtype, but there are two problem with it.
1: gcc dont let me assign double to void *.
2: void *data is a pointer, it must point to somewhere(probably in heap memory).
When I need to change the data 'data' pointer to, and 'data' probably dont know that.
eg:
Code:
int c =3;
void *a = c;
c = 4; //I need c to change for something else, of course.
So guys, is there really a way out?