am trying to figure out how to insert a new number in a linked list after a specified number...i am failing to figure out how to fix in the number in the list...here is the partial code..any help is appreciated

void insert(detailsPtr& head)
{
	
	detailsPtr prev, current,tmp;

	int num,curr_num;

	cout<<"Enter the number which you want your new number to follow:";

	cin >> curr_num;

	cout<<"Enter the number to insert: ";

	cin >> num;

	cout<< endl;
	
	prev=head;

	current=prev->link;

	while(prev->link!=NULL)
    {
       
        if(prev->prod_id==curr_num)
        {
           
			tmp= new details;

			tmp->prod_id=num;

			tmp->link=current;

			prev->link=tmp;
		}

		if(prev->link==NULL)
		{
		
			cout<<"The number you entered cannot be found"<<endl;

		}
	}

}

post the declaration of details

struct details
{

	int prod_id;

	details *link;
};
	
typedef details* detailsPtr;

Insert line 20 inside the while loop and add the statement prev=prev->link; at the end of the loop.

uhuh...that worked...got tangled up and didnt even think of that..thanx

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.