hi, i'm having trouble making something resembling a circular linked list.
here is my code: (i haven't gotten very far)
RingNode class:
1 2 3 4 5 6
class RingNode {
public:
RingNode(constint& i=0 ): data(i), next(NULL){}
private:
int data;
RingNode* next;
function implementation in Ring.cpp:
1 2 3 4 5 6 7 8 9
RingNode* Ring::Insert(constint& d)
{
RingNode* rn = new RingNode;
rn->data = d;
cout << d << ": " << &rn << endl;
//return something later
}
in main.cpp
1 2 3 4
Ring testring;
testring.Insert(1);
testring.Insert(2);
testring.Insert(3);
output:
1 2 3
1: 0x28fec8
2: 0x28fec8
3: 0x28fec8
please help! i don't know why they are all pointing to the same address! i thought dynamic variables were supposed to be persistent (is that the word)? looking forward to your responses, and thanks in advance. :(