[try Beta version]
Not logged in

 
 
Double Linked List handling problems

Mar 27, 2014 at 12:53pm
Hi, Ive done program that reads in coordinates from text file and stores them in double linked list. After coordinates are read in algorithm calculates its importance. User selects number of coordinates he wants to remove. Then program finds double linked list element with lowest importance value and removes it from list. Problem I have is that when search is done and node is find, when trying to remove it, it cant find it. Could you please advice me or point out what i did wrong.


Any advice or help would be appreciated
Last edited on Mar 27, 2014 at 3:27pm
Mar 27, 2014 at 1:20pm
1
2
3
4
5
6
7
8
9
for (current = current->next; current != NULL; current = current->next)
		{
			if (current->F < f)
			{
				f = current->F;
// save the node here as well instead of searching for f again afterwards
        lowest = current;
			}
		}


Then you could remove this line:
lowest = search(f);


Compare this if condition with the condition of your loop
if (p->next != NULL && (p->next->x == x && p->next->y == y && p->next->F == F))

Hint: your loop terminates before u reach the node you want to delete

Have fun
Last edited on Mar 28, 2014 at 6:31pm
Mar 27, 2014 at 1:29pm
Thank you very much, Im gonna try that now
Mar 27, 2014 at 3:25pm
it worked flawlessly after changing loop. Thank you very much Glandy
Topic archived. No new replies allowed.