Help, Assertion problem!!! :(

Reply

Join Date: Apr 2008
Posts: 25
Reputation: kalodakilla is an unknown quantity at this point 
Solved Threads: 0
kalodakilla kalodakilla is offline Offline
Light Poster

Help, Assertion problem!!! :(

 
0
  #1
Apr 11th, 2008
i don't know if i should post it here or in C++ , but please help me, i came into Assertion failure during running this program, and i really don't know why, hope you guys can help, thanks a lot ^^

The program is to copy a linked list from another, the Copy function may look complicated because i'm not experienced enough to simplify it.. Without the destructor, the program runs fine..

#include <iostream.h>

struct node
{
	int data ;
	node * next ;
};

class list
{
private:
	node *head ;
public:
	list() ;
	//~list() ;
	node* Add(node *h , int d) ;
	node* Copy(node *& res , node * copy) ;
	void Input() ;
	void Display() ;
	node* GetHead() ;
	void AssignHead(node *h) ;
};

list::list()
{
	head = NULL ;
}

/*list::~list()
{
	while(head)
	{
		node *current = head->next ;
		delete head ;
		head = current ; 
	}
}*/

node * list::GetHead()
{
	return head ;
}

void list::AssignHead(node *h)
{
	head = h ;
}

node * list::Add(node *h , int d)
{
	if ( !h )
	{
		h = new node ;
		h->data = d ;
		h->next = NULL ;
	}
	else
		h->next = Add(h->next , d) ;
	return h ;
}

void list::Input()
{
	int n ;
	int d ;
	cout << "How many intergers to input: " ;
	cin >> n ;

	for ( int i = 0 ; i < n ; ++i )
	{
		cout << "Interger #" << i+1 << ", please enter: " ;
		cin >> d ;
		head = Add(head,d) ;
	}
}

void list::Display()
{
	node * current = head ;
	while (current != NULL)
	{
		cout << current->data << " " ;
		current = current->next ;
	}

}

node * list::Copy(node *& res , node * copy)
{

	if (copy)
	{
		res = copy ;
		Copy(res->next,copy->next) ;
	}

	return res ;
}



int main()
{
	list integer , a ;

	integer.Input() ;

	integer.Display() ;
	cout << endl ;

	//a.Input() ;

	//a.Display() ;

	node *res = NULL ;
	a.AssignHead(a.Copy(res , integer.GetHead())) ;

	a.Display() ;

	return 0 ;
}
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Help, Assertion problem!!! :(

 
0
  #2
Apr 11th, 2008
Post your thread on C++ section
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 25
Reputation: kalodakilla is an unknown quantity at this point 
Solved Threads: 0
kalodakilla kalodakilla is offline Offline
Light Poster

Re: Help, Assertion problem!!! :(

 
0
  #3
Apr 11th, 2008
thanks, i posted it in C++ section, please lock this topic, sori for wrong post.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Help, Assertion problem!!! :(

 
0
  #4
Apr 11th, 2008
don't mind it. Always post in current section friend . btw i cannot lock this thread. Moderator will do this.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC