struct link
{
	char name[50];
	int value;
	link* next;
}; 

class linklist
{
private :
	link* first;		// ilk baglantiyi tutar
public:
	linklist()
	{
		first=NULL;
	}
	void additem(int d,char a[]);
	void display();
};

void linklist::additem(int d,char a[])
{
	link* newlink=new link;
	newlink->value=d;
	strcpy(newlink->name,a);
	newlink->next=first;
	first=newlink;
}

this is my link list class and what i want to do after adding some nodes, i want to find and exact node using the name kept in node and change its value.
For example
1st nodes name=abc , value=1
2nd nodes name =xyz, value=5
3rd nodes name =anothername, value=40

and i want to write a function or a simple loop that finds node by its name and change its value.Ill be very happy if anyone will help.

Recommended Answers

All 3 Replies

do you know how to search a linked list by using the next pointer? If you do, then its just call strcmp() on every loop iteration to find the desired node.

Am I going to do this for you? Answer: No.

while(strcmp(newlink->name,thename)!=0)
				{
					newlink=newlink->next;
				}
				newlink->value=nextvalue;

i have tried this but it didnt work sadly

i see that i forgot to declare a newlink pointer of link* type and when i do that it works fine , thanks for your kind answer

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.