Linked List returning NULL

My program works correctly except for the fact when i call this function to display whats in the linked list my linked list is returning back as NULL. From what i can understand is i am making a new node tempPtr and so nothing with newStack, newEvan, should be effected by this. Is it somehow linking newStack to tempPtr so when it runs down the linked list its also running down newStack's list? This is all semi new to me and i believe i understand the basics of this but i could be wrong. I have tried debugging this for a couple hours now and cannot figure out why other functions work fine but when i run into this one its returning newEven as NULL. Any help would be appreciated.

EVEN_COUNT is, const string EVEN_COUNT = " integers inserted into Even list:";

1
2
3
4
5
6
7
8
9
10
struct evenLink {
	evenLink *prev;
	int integer;
	evenLink *next;
};

struct evenInfo {
	evenLink *top;
	int length;
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  void DisplayListEven(evenInfo *newStack)
{
	int count = 0;
	evenInfo *tempPtr = NULL;
	tempPtr = newStack;

	cout << endl;
	cout << newStack->length << EVEN_COUNT << endl;

	while (tempPtr->top != NULL) {
		if (count < 10){
			cout << setw(4) << tempPtr->top->integer;
			tempPtr->top = tempPtr->top->next;
			count++;
		}//end if
		else{
			cout << endl;
			cout << setw(4) << tempPtr->top->integer;
			tempPtr->top = tempPtr->top->next;
			count = 1;
		}//end else
	}//end while
	
}


This is the call
DisplayListEven(newEvan);
What is that 'count' thingy doing?

newEvan == newStack == tempPtr, and you change the member 'top' of it.

1
2
3
4
5
6
7
8
9
void foo( const evenInfo * newStack )
{
  const evenLink * node = newStack->top;
  while ( node )
  {
    std::cout << node->integer;
    node = node->next;
  }
}
count is so it only displays 10 items per line.

What you provided solved the issue. Thanks.
Topic archived. No new replies allowed.