i'm beginner in C++,
please help me in display function to display the linked list of my following program
thanks
#include <iostream>
using namespace std;
template< class T >
class Lnode {
public:
T data;
Lnode< T > *next;
};
template< class T >
class List {
public:
int empty();
void add( T data );
T remove();
List() {
sentinel = new Lnode< T >();
sentinel->next = sentinel;
}
void display();
private:
Lnode< T >* sentinel;
};
template< class T >
void List< T >::display()
{
Lnode< T > *q;
cout<<endl;
for(q=p;q!=NULL;q=q->next)
cout<<" "<<q->data;
}
template< class T >
void List< T >::add( T data )
{
Lnode< T > *p;
p = new Lnode< T >();
p->data = data;
p->next = sentinel->next;
sentinel->next = p;
}
template< class T >
T List< T >::remove()
{
T data;
Lnode< T > *node;
if (sentinel->next == sentinel) {
cerr << "ERROR: `remove' called with empty list.\n";
exit(1);
}
node = sentinel->next;
data = node->data;
sentinel->next = node->next;
delete node;
return data;
}
main()
{
List< int > list1;
List< float > list2;
List< char > list3;
list1.add( 5 );
list2.add( 2.7 );
list3.add('c');
cout<<list1.remove();
cout<<list2.remove();
cout<<list3.remove();
}