• (5 Pages)
  • +
  • « First
  • 3
  • 4
  • 5

Data Structures In C++ Tutorial Writing Data Structures using OOP in C++ Rate Topic: ****- 20 Votes

#61 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6036
  • View blog
  • Posts: 23,428
  • Joined: 23-August 08

Posted 17 January 2011 - 12:53 PM

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.
Was This Post Helpful? 0
  • +
  • -

#62 legadema  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 25
  • Joined: 15-December 10

Posted 17 January 2011 - 01:20 PM

View PostJackOfAllTrades, 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
Was This Post Helpful? 0
  • +
  • -

#63 Kenokill  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-April 11

Posted 26 April 2011 - 03:46 PM

first of all great job Born2Code.

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.
Was This Post Helpful? 0
  • +
  • -

#64 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 651
  • View blog
  • Posts: 2,225
  • Joined: 31-December 10

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).
Was This Post Helpful? 0
  • +
  • -

#65 AmazingJr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 12-August 11

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++
Was This Post Helpful? 0
  • +
  • -

#66 snaas.aditya  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-October 11

Posted 12 October 2011 - 08:16 AM

View Postborn2c0de, 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:
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?
Was This Post Helpful? 0
  • +
  • -

#67 Pooja Kuppan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-March 14

Posted 06 March 2014 - 11:11 AM

I have just started learning data structures and your post was very good. Thank you...
But I have a doubt.are the functions push,pop are predefined functions or they are just function names?
Was This Post Helpful? 0
  • +
  • -

  • (5 Pages)
  • +
  • « First
  • 3
  • 4
  • 5