void DeleteNode (char CharToDelete, NodePtr List, int &CharFound)
{
  NodePtr NodeToBeDeleted;
  NodePtr Temp = List;

  if(List->Link == NULL)
	  return;

  while(Temp->Link != NULL)
  {
	  if(Temp -> Ch = CharToDelete)
	  {
		  NodeToBeDeleted = Temp->Link;
		  Temp->Link = NodeToBeDeleted -> Link;
		  delete NodeToBeDeleted;
		  CharFound = 1;
	  }
	  else
		Temp = Temp->Link;
  }

  if(CharFound != 1)
	  CharFound = 0;

}

Im trying to delete a node that holds a character that is entered by the user. The code I have here is going through evertyhing and deleting everything in the list. help?

Anyone please feel free to chime in if you see anything wrong here:

//line #11
if(Temp -> Ch [B]=[/B] CharToDelete)

so, should i change the equal sign to ==?

so, should i change the equal sign to ==?

Have you ever seen an assignment operation take place inside of if()..??

More importantly, were you let down by NIN's release of year zero, in which Trent Reznor claimed to be his greatest artistic effort?

yes ive seen that. and it did work but i dont think that whole code is going to work for me.

and no, i was not let down by year zero. i loved it. weather its greatest artistic effort, i dunno. but i loved it.

Since ye' have a singly-linked list, I believe it is important to 'look ahead' to the next node as much as possible.. because you don't have a pointer to go backwards which can make it hard to affect the previous node.. when you delete a node.. so that it points to the 'next' node..

confused? so am I.

//Try this..    we can now look at the next node in the list and make important decisions
if(Temp->link->Ch == CharToDelete)
{
     NodeToBeDeleted = Temp->Link;
     Temp->Link = NodeToBeDeleted -> Link;
     delete NodeToBeDeleted;

     CharFound = 1;
}

Before when you just had

if(Temp->Ch == CharToDelete)

we attained a pointer to the current node which needed to be deleted.. but had to way to refer back to the previous node, change it's 'link' so that it points past the deleted node.. to the next node in line. With the new and improved if() test condition, we can look one node into the future.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.