struct Letter {
char let;
Letter *next;
};
Please look at the function below called addLETTERS().
int main() {
Letter *Top = 0;
Letter *head = 0;
char letters = 'a';
head = new Letter;
Top = new Letter;
MakeNull(head);
MakeNull(Top);
addLETTERS(Top, head,letters);
return 0;
}
void MakeNull(Letter *newNode){
newNode = new Letter;
newNode->let = 0;
newNode->next = 0;
}
For some odd reason when leaving this function my Linked List losses all its created nodes? Using GDB I can clearly see the function is working and adding the entire alphabet to the list. Can someone run this simple code and tell me why?
struct Letter *addLETTERS(Letter *Top, Letter *head, char& letters) {
if(letters != 'z' + 1){
Top = new Letter;
Top->let = letters++;
Top->next = head;
head = Top;
addLETTERS(Top,head,letters);
}
else {
Top->let = '\0';
Top->next = head;
head = Top;
}
return Top;
}