-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserManager.cpp
More file actions
94 lines (81 loc) · 2.31 KB
/
UserManager.cpp
File metadata and controls
94 lines (81 loc) · 2.31 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 "UserManager.h"
#include <string>
/**
* Empty constructor
*/
UserManager::UserManager(){}
/**
* Function Reads all users from data and store them in linked list then call another method to store each user's friend
*/
void UserManager:: getFileInfo()
{
users = new UserList;
ifstream MyReadFile("C:\\Users\\Lenovo 500\\CLionProjects\\DataStructure_Project\\all-users.in");
while (!MyReadFile.eof())
{
u=new User();
getline(MyReadFile,myText);
int found=myText.find(',');
string userName= myText.substr(0,found);
myText=myText.substr(found+2);
int found2= myText.find(',');
string name=myText.substr(0,found2);
string email=myText.substr(found2+2);
u->setUserName(userName);
u->setName(name);
u->setEmail(email);
users->addUser(u);
}
getFriendInfo();
MyReadFile.close();
}
/**
* get the address of linkedlist
* @return users
*/
UserList* UserManager::getList()
{
return users;
}
/**
*
* @return U
*/
User* UserManager::getUser()
{
return u;
}
/**
* Function read from file the relations of each user and store them in treap
*/
void UserManager::getFriendInfo()
{
string user_name1,user_name2;
Node* current=users->getHead();
while(current!=nullptr)
{
ifstream file_("C:\\Users\\Lenovo 500\\CLionProjects\\DataStructure_Project\\all-users-relations.in");
if(file_.is_open())
{
while(file_>>user_name1>>user_name2)
{
user_name1.assign(user_name1.begin(),user_name1.end()-1);
if(current->user->getUserName()==user_name1)
{
current->user->node=current->user->Add(current->user->node,user_name2,users->searchUser(user_name2));
}
else if(current->user->getUserName()==user_name2)
{
current->user->node=current->user->Add(current->user->node,user_name1,users->searchUser(user_name1));
}
}
}
else
{
cout << "file not opened";
}
file_.close();
current->user->inorder(current->user->node);
current=current->next;
}
}