-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserList.cpp
More file actions
94 lines (91 loc) · 1.7 KB
/
UserList.cpp
File metadata and controls
94 lines (91 loc) · 1.7 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "UserList.h"
#include "User.h"
/**
* Empty constructor make the head and tail of the linkedlist points to nullptr
*/
UserList::UserList()
{
head=nullptr;
tail=nullptr;
}
/**
* Parameterized constructor take a pointer points to a suer
* @param u: equal the User to U
*/
UserList::UserList(User* u)
{
head->user=u;
tail=head;
head->next=nullptr;
tail->next=nullptr;
}
/**
* Function to add a new user in linkedlist
* @param u a new user will be added in linkedlist
*/
void UserList::addUser(User* u)
{
Node *temp=new Node();
temp->user=u;
temp->next=nullptr;
if (head==nullptr)
{
tail=head=temp;
}
else
{
tail->next=temp;
tail = tail->next;
}
}
/**
* print whole information oof each user in linkedlist
*/
void UserList::printList()
{
Node* current= head;
while(current!=nullptr)
{
current->user->print();
current=current->next;
}
}
/**
*
* @param userName: the userName of a specific user in linkedlist
* @return address oof this user
*/
User* UserList::searchUser(string userName)
{
Node* current= head;
while(current!=nullptr)
{
if(current->user->getUserName()==userName)
{
return current->user;
}
current=current->next;
}
return nullptr;
}
/**
* to get the address of the head of linkedlist
* @return head
*/
Node* UserList::getHead()
{
return head;
}
/**
* destroy elements
*/
UserList::~UserList ()
{
Node * curr =head;
while(curr!=NULL)
{
head=head->next;
delete curr;
curr=head;
}
}