This seems weird to me
CODE
x.InsertAtEnd(x,a);
If x is a LikedList, a standard version of it or your implementation, why should you pass the same linked list to your insert method as parameter ?
Got the answer, the parameter is not used
CODE
// what do you do with X ?
public void InsertAtEnd(LinkedList56 x, int a){
//create new node
node q = new node();
node p = new node();
q.data = a;
q.next = null;
//empty list
if(first == null){
first = q;
}
//list is not empty
else
p = first;
while(p.next != null){
p = p.next;
}
p.next = q;
}
Your constructor of node does not initialized "data" OK will be 0 but initialize "first" to null
CODE
node doublepointer = new node(); // creates a node "data" not initialized
pointer = first; // this might be null
doublepointer = pointer.next;
while(doublepointer.data != a){ // doublePointer points to null