Searching through a linked list for all players with the same team

I'm trying to search through a linked list of players for players that have the same team name and output the ones who have the same team. So far this is what I have but when I run the program and try to print the players with the inputted team name it crashes.

Playerlklist.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 #include "PlayerlkList.h"

PlkList::PlkList()
{
	pLP = NULL;
}

void PlkList::insert(PlayerInfo playerObj1)
{
	PNode *p = new PNode;

	p->PData = playerObj1;

	p->next = pLP;

	pLP = p;
}

void PlkList::printPL(string teamName1)
{
	PNode *p = pLP;

	if (pLP == NULL)
	{
		cout << "The list is empty" << endl;
	}
	else if (search(teamName1) == true)
	{ 
		while (p != NULL)
		{
				if (p->PData.getName() == teamName1)
				{
					
					cout << "[" << p->PData.getName() << ", " << p->PData.getNumber() << "] ->";
					
					p = p->next;
				}
				else
				{
					p = p->next;
				}
		}
			

	}
	else if (search(teamName1) == false)
	{
		cout << "No Players on that team";
	}
}

void PlkList::print()
{
	PNode *p = pLP;
	cout << "[" << p->PData.getName() << ", " << p->PData.getNumber() << "] ->";
}



bool PlkList::search(string teamName1)
{
	PNode *p = sL;

	while (p != NULL)
	{
		if (p->PData.getTeamName() == teamName1)
			return true;
		else
			p = p->next;
	}
	return false;
}


main
1
2
3
4
cout << "Enter a team to list the players from: ";
			cin >> teamName1;

			PObj1.printPL(teamName1);
Topic archived. No new replies allowed.