LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-28-2004, 05:05 AM   #1
antony_csf
Member
 
Registered: Jun 2004
Posts: 51

Rep: Reputation: 15
C program problem on delete duplicated nodes in linked list !


I am writting a function to remove duplicated nodes in linked list

but it run out of memory!!

Any C expert can tell me what error on my code!!

many thx
Code:
typedef struct node *NodePtr;

struct node
{
	int num;
	NodePtr next;
};
.
.
.
.
void delete_duplicated_nodes(NodePtr p)
{	
	NodePtr temp_root	= p;
	NodePtr temp_pre	= p;
	NodePtr temp_move	= p->next;


	while(temp_root != NULL){


		while(temp_move != NULL){
			if(temp_move->num == temp_root->num){
				temp_move = temp_move->next;		
				free(temp_pre->next);				
				temp_pre->next = temp_move;			
			}else{
				temp_pre = temp_pre->next;			
				temp_move = temp_move->next;
			}
		}


		temp_root	= temp_root->next;				
		temp_pre	= temp_root->next;				
		temp_move	= temp_root->next->next;		
	}

}

Last edited by antony_csf; 10-28-2004 at 05:21 AM.
 
Old 10-28-2004, 05:05 AM   #2
antony_csf
Member
 
Registered: Jun 2004
Posts: 51

Original Poster
Rep: Reputation: 15
Unhappy Re: C program problem on delete duplicated nodes in linked list !

sorry error post!!

Last edited by antony_csf; 10-28-2004 at 05:11 AM.
 
Old 10-28-2004, 10:42 AM   #3
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Out of memory? You're not allocating any in your code. What's the exact error you're getting?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
concepts a linked list program in c ssg14j Programming 4 08-19-2005 10:10 AM
linked list + c dilberim82 Programming 5 05-04-2005 11:48 PM
linked lists w/ nodes? |2ainman Programming 1 05-19-2004 01:32 AM
imple,menting a linked list in c program in linux bprasanth_20 Programming 17 10-25-2003 02:06 AM
C++ linked list fun chens_83 Programming 2 08-04-2003 07:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration