pointer problems...

I am creating a linked list of int values. I cannot figure out why the function below doesn't find values that are in the list.

1
2
3
4
5
6
7
8
9
10
11
12
//at function returns the index of a value
//that the programmer passes to the funtion.
int iVec::at(int n){
	Node *current=m;//current=first node in list.
	for(int count = 0; count<size();count++){
		if(n==current->data)
			return count;
		else
			current=current->next;
	}
	return NULL;
}
Its possible that the error is in the outside code.
What good would returning an integer index do, anyway. Wouldn't it make more sense to return a pointer to the matching node?

Also, NULL == 0, so you can't tell if a return value of 0 means the first element matched or if there were no matches.

+ what Galik said.
Topic archived. No new replies allowed.