Witam
Podany kod dodaje elementy z klasy "student" i "grupa" do list. Mam pytanko czy mogę jakoś użyć jednej funkcji push ? czy muszą istnieć dwie osobne dla każdej z klas ?
class student {
char imie;
char nazwisko ;
};
class grupa {
char nazwa;
char kierunek ;
};
typedef struct listS{
struct listS *next,*prev;
student key;
}listaS;
typedef struct listG{
struct listG *next,*prev;
grupa key;
}listaG;
void push(listaS *&head,student x){
listaS *nowy= new listaS;
listaS *tmp= new listaS;
nowy->key = x;
nowy->next = NULL;
if(head) {
tmp=head;
while(tmp->next) tmp=tmp->next;
tmp->next=nowy;
nowy->prev = head;
}
else {
head=nowy;
tmp->prev=NULL;
}
}
void pushG(listaG *&head,grupa x){
listaG *nowy= new listaG;
listaG *tmp= new listaG;
nowy->key = x;
nowy->next = NULL;
if(head) {
tmp=head;
while(tmp->next) tmp=tmp->next;
tmp->next=nowy;
nowy->prev = head;
}
else {
head=nowy;
tmp->prev=NULL;
}
}