-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFb.h
More file actions
131 lines (108 loc) · 3.82 KB
/
Fb.h
File metadata and controls
131 lines (108 loc) · 3.82 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
WeChat: cstutorcs
QQ: 749389476
Email: tutorcs@163.com
// Friendbook ADT
// For simplicity, people are identified by their names, so two people
// cannot share the same name.
// !!! DO NOT MODIFY THIS FILE !!!
#ifndef FB_H
#define FB_H
#include "List.h"
typedef struct fb *Fb;
struct recommendation {
char *name;
int numMutualFriends;
};
////////////////////////////////////////////////////////////////////////
/**
* Creates a new instance of Friendbook
*/
Fb FbNew(void);
/**
* Frees all memory allocated to the given Friendbook instance
*/
void FbFree(Fb fb);
/**
* Returns the number of people who have been added to Friendbook.
*/
int FbNumPeople(Fb fb);
/**
* Creates a Friendbook account for the given person. Returns true if
* successful, and false if a person with that name already exists.
*/
bool FbAddPerson(Fb fb, char *name);
/**
* Returns true if the given person has been added to Friendbook, and
* false otherwise.
*/
bool FbHasPerson(Fb fb, char *name);
/**
* Returns a list of all people who have been added to Friendbook.
*/
List FbGetPeople(Fb fb);
/**
* Checks whether two people are friends. Assumes that they both have a
* Friendbook account. Returns true if they are friends, and false
* otherwise.
*/
bool FbIsFriend(Fb fb, char *name1, char *name2);
////////////////////////////////////////////////////////////////////////
// Your tasks
/**
* Friends two people. Assumes that they both have a Friendbook account,
* and that they are not the same person. Returns true if the operation
* was successful, and false if they were already friends.
*/
bool FbFriend(Fb fb, char *name1, char *name2);
/**
* Returns the number of friends the given person has. Assumes that the
* person has a Friendbook account.
*/
int FbNumFriends(Fb fb, char *name);
/**
* Returns a list of the names of all the mutual friends of two people.
* Assumes that the people have been added to Friendbook, and that they
* are not the same person.
*/
List FbMutualFriends(Fb fb, char *name1, char *name2);
/**
* Unfriends two people. Assumes that they both have a Friendbook
* account, and that they are not the same person. Returns true if the
* operation was successful, and false if the people were not friends.
*/
bool FbUnfriend(Fb fb, char *name1, char *name2);
/**
* Generates friend recommendations for a person and stores them in the
* given recs array. Returns the number of recommendations stored.
*
* This function should only recommend people who are friends of friends
* of the given person. In other words, it should only recommend people
* who share at least one mutual friend with the person. Obviously, it
* should not recommend someone who is already the person's friend.
*
* It is possible for there to be no recommendations if, for example,
* the person is already friends with everyone.
*
* Each recommendation consists of the name of a person and the number
* of mutual friends they share with the given person.
*
* Recommendations should be sorted in descending order on the number of
* mutual friends shared. If two people share the same number of mutual
* friends, they may be sorted in any order.
*/
int FbFriendRecs1(Fb fb, char *name, struct recommendation recs[]);
////////////////////////////////////////////////////////////////////////
// Optional task
/**
* Generates recommendations for a person based on friend closeness.
* Returns a list of the names of all the recommended friends.
*
* Friends of friends should be recommended first, followed by friends
* of friends of friends, and so on. People who are the same "distance"
* from the given person can be recommended in any order.
*
* Generate a maximum of 20 recommendations. If there are more than 20
* recommendations, ignore the rest.
*/
List FbFriendRecs2(Fb fb, char *name);
#endif