templated que class

I am trying to make a que class so that I can store any type of data in node such as string or int or double or any other class .....

what am I doing wrong?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<iostream>
using namespace std;
template <class T>
class node
{
    public:
        T data;
        node<T> *link;
        node()
        {
            link =NULL;
        }
        node( node<T>& d)
        {
            data = d.data;
            link = NULL;
        }
        void setNode(T d)
        {
            data = d;
        }
        T getData()
        {
            return data;
        }
        node getNode()
        {
            return *link;
        }
        friend ostream& operator <<(ostream& out , const T &obj)
        {
                out <<"   " <<obj.data;
        }
};
template<class T>
class kue
{
    private:
        node<T> *head;
    public:
        kue()
        {
            head = NULL;
        }
        void push_back(node<T> n)
        {
            if(head == NULL)
            {
                head = new node<T>(n);
            }
            else
            {
                node<T> *temp = head;
                while(temp->link != NULL)
                {
                    temp = temp->link;
                }
                temp->link = new node<T>(n);
            }
        }
        void show_kue()
        {
            node<T> *temp = head;
            while(temp->link != NULL)
            {
                cout << temp;
                temp = temp->link;
            }
            cout << temp->data;
        }
};
int main()
{
    kue<node<int> > k;
    node<int> n;
    n.setNode(1);
    node<int> n2;
    n2.setNode(2);
    node<int> n3;
    n3.setNode(3);
    k.push_back(n);
    k.push_back(n2);
    k.push_back(n3);
    k.show_kue();
    return 0;
}
Replace kue<node<int> > k; with kue<int> k; on line 74.
Great!!!

and also on line 66 I have been "cout-ing" temp instead of temp->data .
Topic archived. No new replies allowed.