Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task 1 - Friending :) Implement the FbFriend ( ) function in Fb . c , which takes the names of two people, and friends
Task Friending :)
Implement the FbFriend function in Fbc which takes the names of two people, and friends them if they are not already friends. The function should return true if the people were not friends and were successfully friended, and false if the two people were already friends.
You should implement your function so that the adjacency lists are kept in ascending order. For example, in the example in the Background section, since Harry is friends with Ron and Hermione should appear before in Harry's adjacency list.
You can assume that the two people exist and are not the same person.
We have provided a function newAdjNode which creates a new adjacency list node.
Is inserting into an adjacency list similar to a problem that you have solved in a previous lab exercise?
Once you think you've got the function working, test it by recompiling with make and running the runFb program. You can test whether your function works using the add person f friend and s friendship status commands. For example:
runFb
Friendbook v
Enter to see the list of commands.
Harry
Harry was successfully added to Friendbook!
Ron
Ron was successfully added to Friendbook!
Hermione
Hermione was successfully added to Friendbook!
s Ron Hermione
Ron and Hermione are not friends.
f Ron Hermione
Successfully friended Ron and Hermione!
s Ron Hermione
Ron and Hermione are friends.
s Harry Ron
Harry and Ron are not friends.
f Harry Ron
Successfully friended Harry and Ron!
s Harry Ron
Harry and Ron are friends.
s Ron Hermione
Ron and Hermione are friends.
s Harry Hermione
Harry and Hermione are not friends.
You can run the above test case with the following command:
runFb e testsfriendtxt
This command runs the runFb program and causes it to read Friendbook commands from the file testsfriendtxt The e option which stands for "echo" causes the program to print out the commands to the terminal as they are being run, which makes it easy to see which operations are being performed.
When you're certain that the function works correctly, determine its worst case time complexity and write in analysis.txt along with an explanation. The time complexity should be in terms of
n
where
n
is the total number of people.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started