-
deleting all occurances of x in a linked list
This code is supposed to delete all occurances of d in a linked list.
Anyone have any idea why this doesnt work? It's as if it doesnt
advance current->link because it never exits the loop.
Im not including any other code, because i can not modify that code
and the assignment is to make use of the code provided. deleteNode is
pretty straight-forward, just removes a node from the list, accepting
an int or float etc...
template<class Type>
void linkedListType<Type>::deleteall(Type d)
{
nodeType<Type> *current, *deleteme;
current = first;
while (current != NULL)
{
if(current->info == d)
deleteme = current;
deleteNode(deleteme->info);
current=current->link;
}
}
If this code is totally wrong or inefficient, can i get some advice on how
to do this?
Thanks,
N. Labelle
-
Re: deleting all occurances of x in a linked list
"N.Labelle" <nalabe01@wsc.edu> wrote:
>
>This code is supposed to delete all occurances of d in a linked list.
>Anyone have any idea why this doesnt work? It's as if it doesnt
>advance current->link because it never exits the loop.
>
>Im not including any other code, because i can not modify that code
>and the assignment is to make use of the code provided. deleteNode is
>pretty straight-forward, just removes a node from the list, accepting
>an int or float etc...
>
>template<class Type>
>void linkedListType<Type>::deleteall(Type d)
>{
>nodeType<Type> *current, *deleteme;
>current = first;
>while (current != NULL)
>{
>if(current->info == d)
>deleteme = current;
>deleteNode(deleteme->info);
right here you have deleted ALL of the info associated with the node,
INCLUDING the link!!!!!... you should do the current=current->link BEFORE
you do the delete.
>current=current->link;
>}
>}
>
>If this code is totally wrong or inefficient, can i get some advice on how
>to do this?
>
>Thanks,
>
>N. Labelle
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks