Please Tell me what is wrong in this program and how it can be solved?
#include <iostream>
using namespace std;
class Node {
private:
int data;
Node *next;
Node *pre;
public:
Node (){
data = 0;
pre = next = NULL;
}
void setdata(int d) {data = d;}
int getdata(){return data;}
void setNext(Node *n) {next = n;}
Node *getNext(){return next;}
void setPrevious(Node *n) {pre = n;}
Node *getPrevious(){return pre;}
};
class Linkedlist{
public:
Node *First;
Node *Last;
Node *Pre;
int size;
void add(Node *n){
if (size == 0)
{
First = Last = n;
}
else
{
n->setPrevious(Last);
Pre = Last;
Last->setNext(n);
Last = n;
}
size ++;
}
void traverseforward(){
Node *n = First;
while(n != NULL){
cout<<n->getdata()<<endl;
n = n->getNext();
}
}
void traversereverse(){
Node *n = Last;
while(n != NULL){
cout<<n->getdata()<<endl;
n = n->getPrevious();
}
}
};
int main() {
Node n1, n2, n3, n4;
n1.setdata(20);
n2.setdata(30);
n3.setdata(40);
n4.setdata(50);
Linkedlist list;
list.add(&n1);
list.add(&n2);
list.add(&n3);
list.add(&n4);
list.traverseforward();
}