Linked lists aren't usually copied in that way, but feel free to implement a copy constructor and assignment operator. Tutorials aren't necessarily meant to be a drop-in for every situation.
Data Structures In C++ Tutorial Writing Data Structures using OOP in C++
#62
Posted 17 January 2011 - 01:20 PM
JackOfAllTrades, on 17 January 2011 - 12:53 PM, said:
Linked lists aren't usually copied in that way, but feel free to implement a copy constructor and assignment operator. Tutorials aren't necessarily meant to be a drop-in for every situation.
what way do you mean? like in the example i gave?
chain = ll
another error occurs when doing a thing like this
void foo(linklist lk){
lk.append(5001);
}
int main(){
linklist ll;
ll.append(1);
ll.append(2);
ll.append(3);
foo(ll);
ll.display();
}
just passing the linklist as an argument to a simple function produces errors
i'm just suggesting u guys to add and explain this thing, thank u
#63
Posted 26 April 2011 - 03:46 PM
first of all great job Born2Code.
The function,
Seems to cause problems for me in visual (you mentioned it might not work). I noticed that del() is deleting the node and thus the pointer q->r does not point to NULL (not sure if this is compiler specific) so that when destruct() is called on this pointer, q != NULL returns true when in fact it shouldn't since it was deleted. So that destruct(q->l)
causes a violation. I fixed this by changing this function a little as follows,
Notice "TLeaf *t = q->r;" takes the address of the right child before it's parent is deleted. Well this fixed the problem for me using visual c++, I would like to know why this doesn't cause a problem with other compilers.
The function,
void tree::destruct(TLeaf *q){
if(q != NULL){
destruct(q->l);
del(q->data);
destruct(q->r);
}
}
Seems to cause problems for me in visual (you mentioned it might not work). I noticed that del() is deleting the node and thus the pointer q->r does not point to NULL (not sure if this is compiler specific) so that when destruct() is called on this pointer, q != NULL returns true when in fact it shouldn't since it was deleted. So that destruct(q->l)
causes a violation. I fixed this by changing this function a little as follows,
void tree::destruct(TLeaf *q){
if(q != NULL){
destruct(q->l);
TLeaf *t = q->r;
del(q->data);
destruct(t);
}
}
Notice "TLeaf *t = q->r;" takes the address of the right child before it's parent is deleted. Well this fixed the problem for me using visual c++, I would like to know why this doesn't cause a problem with other compilers.
#64
Posted 28 May 2011 - 01:26 PM
I copied & pasted the code for the binary tree and then compiled it with g++. It compiles fine, but at the end of main, I get a segmentation fault. When I run gdb, it said the seg fault occurred in tree::del(int).
#65
Posted 12 August 2011 - 06:19 PM
Is there any chance of the double linked list code being put up?
Or could someone advise me on how to change the single linked list code?
I know i should have node *prev; to hold the pointer of the previous node but i'm not sure how to exaclty implement it in C++
Or could someone advise me on how to change the single linked list code?
I know i should have node *prev; to hold the pointer of the previous node but i'm not sure how to exaclty implement it in C++
#66
Posted 12 October 2011 - 08:16 AM
born2c0de, on 23 May 2006 - 10:40 AM, said:
I think you're confused shikha
endl just inserts a new line character in the output statement and is not used to end a statement.
I can also use it like this:
The semicolon is always used to mark the end of a statement.
endl just inserts a new line character in the output statement and is not used to end a statement.
I can also use it like this:
cout<<endl<<"Got it?";
The semicolon is always used to mark the end of a statement.
hey u said, thats absolutely right but its taking space now what?
|
|








MultiQuote


|