# Why can't my link list find integers 7 and 8??

This is a discussion on Why can't my link list find integers 7 and 8?? within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <vector> //#include <list> using namespace std; struct Node { int data; Node *next; Node(int d, Node ...

1. ## Why can't my link list find integers 7 and 8??

Code:
```#include <iostream>
#include <vector>
//#include <list>
using namespace std;

struct Node
{
int data;

Node *next;

Node(int d, Node *n) : data(d), next(n)
{}
};

class List
{
public:

List()
{
//cout << "int() is: " << int() << endl;

}

{

/*if(it->next != NULL)
{

tail = new Node(dataX, it->next);

tail->data = dataX;
//cout << "tail->data is: " << tail->data << endl;
tail->next = NULL;
return;
}*/

if(it->next == 0)
{
// can't find 7 or 8 due to a problem in here.
n1.data = it->data;
//n1.next = it->next;
cout << "yes, this is definately working" << endl;
cout << n1.data << endl;
}

while(it->next != 0)// && it->next->data < dataX)
{
int ggg = 0;
//cout << ++ggg << "this number" << endl;

n1.data = it->data;
n1.next = it->next;
//	cout << n1 << " and " << n1.data << endl;
it = it->next;
//cout << "hello world" << endl;
cout << it->data << endl;

//it->next = new Node(dataX, it->next);

}

//cout << "it->data is: " << it->data << endl;

//if(it->next == NULL)
//n1->data = dataX;
//n1 = it->next;
it->next = new Node(dataX, it->next);

}

bool Count(int y)
{
//cout << vTail[-1] << endl;
return 1;

}

void RemoveAll(int z)
{
//cout << "it->next is right now: " << it->data << endl;

//while(it->next == NULL) // && it->next->data < z)
//{
//cout << "hola" << endl;
it = it->next;

//	cout << "hola " << it->next << endl;
//}
//{
//	Node *hold = it->next;
//	it->next = hold->next;

//	delete hold;

//	while(it != 0)
//	{
//cout << "now it's: " << it->data << "->" << endl;

//		it = it->next;
//	}

//}

if(it->next != NULL)
{
cout << "yes this works" << endl;
Node *hold = it->next;
it->next = hold->next;
//cout << "hold->next is: don't expect to print->: " << hold->next << endl;

delete hold;

//cout << "hold->next is now: " << hold->data << endl;

//cout << "while remove, it->data is: " << it->data << endl;
}

//cout << "after remove, it->data is: " << it->data << endl;

}

int Contains(int b)
{
return 1;
}

void display()
{
{

while(it != 0)
{
cout << it->data << "->";

it = it->next;
//cout << it->data << "->";
}

}

}

private:
Node *tail;

//List *pNext;

vector<int> vTail;

};

Node *find_entry(Node *lptr, int match)
{
while(lptr != 0)
if(lptr->data == match)
{
cout << "match is: " << match << endl;
return(lptr);
}
else
//cout << "lptr->data is: " << lptr->data << endl;
lptr = lptr->next;

return (0);

}

int main()
{
List list;

Node *find_entry(Node *lptr, int match);
//Node n1, n2, n3;
Node *lptr, *list_start;
//Node n1(NULL, NULL) = &list_start;
int i, search;

//cout << list.Count(9) << endl; //this should print 0

cout << "list start is: " << list_start->data << endl;
list.display();

cout << "Enter a value to locate: ";
cin >> search;

lptr = find_entry(list_start, search);
//cout << "this is important: " << lptr->data << endl;

if(lptr != 0)
cout << "found " << lptr->data << "." << endl;
else

list.RemoveAll(7);
list.RemoveAll(10);
list.RemoveAll(9);
list.display();

//lptr = list.FindEntry(list_start, match);

/*if(lptr != 0)
cout << "Found: " << lptr->data << endl;
else

/*if(list.Contains(12))
cout << "Found 12" << endl; //this should print
else
cout << "Error" << endl;

if(!list.Contains(15))
cout << "Did not find 15" << endl; //this should print
else
cout << "Error" << endl;*/

//for(int dataX = 0; dataX < 10; dataX++)

//cout << list.Count(7) << endl; //should print 2, since there are 2 7's in the list

list.RemoveAll(0);

//cout << list.Count(7) << endl; //should print 0

cout << endl;

return 0;
}```
in my link list, I'm inserting the integers 7, 8, 9, 10, and 11.

I have a search function: "find_entry" under class list.

This function can find the 9, 10, and 11 that I inserted into my list, but it can't find 7 or 8.

The problem lies within class List, member function Add, somewhere inside the first if statement.

I don't know why n1.data isn't getting assigned to it->data correctly.

Could someone please point me in the right direction?

Thanks

2. Code:
```Node *lptr, *list_start;