[solved] – Question 82355
//Answer Code attached; I try to compile it but it doesn’t work
#include<iostream>
#include<ctime>
#include <string>
using namespace std;
class List
{
struct Node
{
int data;
Node *next;
};
Node *head;
public:
List()
{
head = NULL;
}
~List()
{ // delete the list while(head != NULL) {
Node * n = head->next;
delete head;
head = n;
}
void add(int value)
{
Node * n = new Node;
n->data = value;
n->next = head;
head = n;
}
void show()
{
while(head !=NULL)
{
Node * n = head->next;
cout<< head->data <<“, “; head = n;
}
cout << endl;
}
};
int main()
{
time_t t=time(NULL);
List MyList;
MyList.add(5);
MyList.add(12);
MyList.add(24);
MyList.add(32);
MyList.add(47);
MyList.add(54);
MyList.add(65);
MyList.show();
cout<<“Today is: “<< ctime(&t) << endl;
system(“pause”);
return 0;
}
Expert Answer
OR

