Brute Force return issue.

I've implemented a Brute Force search into my double ended list class but have encountered a small issue. When I return the value, it returns the rest of the end of the string also, not just that one element. I'm not sure what's causing this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
	ListElement *BruteSearch(const char* string)
	{
		ListElement *iter = new ListElement;
		iter = this;

		while(iter != NULL)
		{
			if(strcmp(string, iter->mData) == 0)
				return iter;
			
			iter = iter->Next();
		}
		return 0;
	}
1
2
3
4
5
	ListElement *BruteSearch(const char* string)
	{
		ListElement *iter = new ListElement; //allocate a new element
		iter = this; //loose the reference to the new element
	}

When I return the value, it returns the rest of the end of the string also, not just that one element
I don't understand, could you provide an example
Basically it prints out the rest of the ListElements that follow after the element that has been found and supposed to be printed out.
show us the code that does the printing.
Topic archived. No new replies allowed.