I'm new to generic programming and I just cant figure out what is wrong in this . The program is supposed to make a linked list using class.
I have used 2 classes so that a single object of class LL can be used to manipulate a linked list . I want the program to work for both integers and characters . When I try without the generic part , the code is working perfectly !
Somebody please help me ! My exam is tomorrow!!
#include<iostream>
#include<stdlib.h>
using namespace std;
template<class T>
class node
{
T data;
node * link;
friend class ll;
public:
};
template<class T>
class ll
{
node * <T>start;
public:
template<class T>
ll()
{
<T>start=NULL;
}
//void search();
void add();
void disp();
//void remove();
};
template<class T>
void ll::add()
{
T x;
node * <T>temp=new node;
cout<<"\nData : ";
cin>>x;
temp->data=x;
temp->link=start;
start =temp;
}
template<class T>
void ll::disp()
{
node *<T>ptr;
T x;
ptr =start;
while(ptr!=NULL)
{
x=ptr->data;
cout<<x<<"\n";
ptr=ptr->link;
}
}
int main()
{
ll <int>list1;
int ch;
while(1)
{
cout<<"\n1.Add\n2.Display\n3.Exit\nEnter choice : ";
cin>>ch;
switch(ch)
{
case 1 : list1.add(); break;
case 2 : list1.disp(); break;
case 3 : exit(0); break;
default : cout<<"Invalid Entry "; break;
}
}
return 0;
}