Question: #include using namespace std; class Node { public: Node(int f) { info = f; next = NULL; } int getInfo() { return info; } Node
#include
using namespace std;
class Node
{
public:
Node(int f)
{
info = f;
next = NULL;
}
int getInfo() { return info; }
Node * getNext() { return next; }
void setInfo(int f) { info = f; }
void setNext(Node * n) { next = n; }
void print() { cout << info << "->"; }
private:
int info;
Node * next;
};
class List
{
public:
List() { listData = NULL; }
void insert(Node * n)
{
if (listData == NULL)
listData = n;
else
{
n->setNext(listData);
listData = n;
}
}
void print()
{
Node * p = listData;
while (p != NULL)
{
p->print();
p = p->getNext();
}
}
private:
Node * listData;
};
int main()
{
List lst;
for (int i = 0; i < 20; i++)
{
Node * nd = new Node(i);
lst.insert(nd);
}
lst.print();
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
