J
Jonas Ferreira
Hi everyone, I'm trying to code a linked list example and everything
was working fine. Then I started to code my clear() (to clear my list)
but it won't work. Here is the code:
class list {
protected:
struct node {
char* data;
node* prev;
node* post;
node(): prev(NULL),post(NULL) {};
node(char* u): data(u),prev(NULL),post(NULL) {};
};
node* head;
node* tail;
int QS,qtd;
public:
list(int size,char* u);
void go(char* u);
void show();
void clear();
};
void list::clear()
{
node *L,*D;
int I;
for (L=head;L!=tail;L=D) { D=L->post; delete L; };
cout << "clear(): " <<endl;
};
I didn't post all the code here but I can send the rest of it if anyone
needs (wishes).
Well, I can compile it and even run it, but "clear()" won't work.
I wrote a main.cpp just to populate the list, then show its nodes,
clear the list, then show its nodes again (it should be 0 nodes, after
the clear()), but after the clear, its nodes are the very same before
the clear.
---main.cpp----
#include stuff
int main() {
list L(20,"teste");
L.go("papa01");
L.go("papa02");
L.go("papa03");
L.go("papa04");
L.show();
L.clear();
L.show();
};
----------------
the output is:
----
papa01
papa02
papa03
papa04
clear():
papa01
papa02
papa03
papa04
-----
If anyone can help just saying what is wrong, I would appreciate it.
Thanks, Jonas.
ps: Sorry about the poor english.
was working fine. Then I started to code my clear() (to clear my list)
but it won't work. Here is the code:
class list {
protected:
struct node {
char* data;
node* prev;
node* post;
node(): prev(NULL),post(NULL) {};
node(char* u): data(u),prev(NULL),post(NULL) {};
};
node* head;
node* tail;
int QS,qtd;
public:
list(int size,char* u);
void go(char* u);
void show();
void clear();
};
void list::clear()
{
node *L,*D;
int I;
for (L=head;L!=tail;L=D) { D=L->post; delete L; };
cout << "clear(): " <<endl;
};
I didn't post all the code here but I can send the rest of it if anyone
needs (wishes).
Well, I can compile it and even run it, but "clear()" won't work.
I wrote a main.cpp just to populate the list, then show its nodes,
clear the list, then show its nodes again (it should be 0 nodes, after
the clear()), but after the clear, its nodes are the very same before
the clear.
---main.cpp----
#include stuff
int main() {
list L(20,"teste");
L.go("papa01");
L.go("papa02");
L.go("papa03");
L.go("papa04");
L.show();
L.clear();
L.show();
};
----------------
the output is:
----
papa01
papa02
papa03
papa04
clear():
papa01
papa02
papa03
papa04
-----
If anyone can help just saying what is wrong, I would appreciate it.
Thanks, Jonas.
ps: Sorry about the poor english.