I don't know how to get the program to display properly any tips? Also would anyone guide me on how the logic works for deallocating all this memory please.
#include <iostream>
#include <cstdlib>
#include <windows.h>
using namespace std;
struct Entry
{
char name[23];
int age;
Entry *next;
};
// Prototype
Entry* buildList(int);
Entry* getNewEntry(int);
void displayList(Entry *);
void displayEntry(Entry *);
int main(int argc, char *argv[])
{
int numNodes;
cout << "How many nodes? ";
cin >> numNodes;
Entry *myList = buildList(numNodes);
displayList(myList);
/*
Entry *myEntry = getNewEntry();
displayEntry(myEntry);*/
Sleep(4000);
return 0;
}
Entry* getNewEntry(int numNodes)
{
Entry *newOne = new Entry;
cout << "Name: ";
cin >> newOne->name;
cout << "Age: ";
cin >> newOne->age;
if(numNodes == 3)
newOne->next = NULL;
return newOne;
}
Entry* buildList(int numNodes)
{
// Start of List
Entry *startList = NULL;
for(int i = 0; i < numNodes; i++)
{
// Build Node
Entry *newOne = getNewEntry(numNodes);
if(!newOne)
{
cout << "No memory allocated." << endl;
exit(0);
}
startList = newOne;
newOne->next = startList;
}
return startList;
}
void displayList(Entry *dInfo)
{
for(Entry *current = dInfo; current != NULL; current->next)
displayEntry(current);
}
void displayEntry(Entry *dInfo)
{
cout << dInfo->name << " " << dInfo->age << endl;
}