﻿1
00:00:00,500 --> 00:00:07,970
‫So now we're going to create the ad edge function and ad edge is going to connect to vertices, which

2
00:00:08,000 --> 00:00:10,970
‫in this case will be represented like this.

3
00:00:10,970 --> 00:00:15,740
‫And when we add that edge, we're going to be doing this.

4
00:00:16,310 --> 00:00:21,500
‫So let's put the adjacency list back like this and we'll start writing our function.

5
00:00:21,770 --> 00:00:26,270
‫We'll pass it to vertices vertex one and vertex two.

6
00:00:27,020 --> 00:00:38,060
‫So we're going to say adjacency list at Vertex one and we'll say that Vertex one is a when we do this,

7
00:00:38,060 --> 00:00:42,440
‫it returns the value in the key value pair.

8
00:00:42,770 --> 00:00:46,610
‫So it is returning this unordered set.

9
00:00:47,000 --> 00:00:55,160
‫And because we've returned an unordered set, we can now use the member functions that are associated

10
00:00:55,160 --> 00:01:06,020
‫with unordered sets and we can say dot insert vertex two, which does this, and then we can do the

11
00:01:06,020 --> 00:01:15,500
‫same thing for the other vertex pass that one vertex one which adds a to that unordered set.

12
00:01:16,070 --> 00:01:22,880
‫So we can only do this if the two vertices that were creating an edge between exist.

13
00:01:23,920 --> 00:01:31,570
‫So we'll have this if statement that makes sure that vertex one and vertex two both exist.

14
00:01:32,020 --> 00:01:39,640
‫And if they do, we'll run these two lines of code and the if statement and will return true if one

15
00:01:39,640 --> 00:01:42,130
‫or both of them do not exist.

16
00:01:42,580 --> 00:01:47,080
‫We'll skip the if statement and we'll return false.

17
00:01:47,590 --> 00:01:50,470
‫So that is all of our code for add edge.

18
00:01:50,740 --> 00:01:54,610
‫So now let's flip over to VS Code and take a look at this.

19
00:01:55,270 --> 00:02:03,730
‫So there is our add edge member function added to our graph class and I'll scroll up and in our main

20
00:02:03,730 --> 00:02:10,480
‫function we'll create our graph with this line and that will create our two vertices A and B with these

21
00:02:10,480 --> 00:02:17,470
‫two lines and with this line, we will print that out and I'll run this and you can see that our graph

22
00:02:17,470 --> 00:02:23,950
‫contains those two vertices, but we don't have an edge between them yet, so I'm going to come up here.

23
00:02:25,050 --> 00:02:29,910
‫And I'll add this line, and this adds an edge between A and B.

24
00:02:30,360 --> 00:02:38,220
‫So now I'll run this and you can see that we now have an edge between those vertices and that is our

25
00:02:38,220 --> 00:02:41,160
‫function for ADD Edge.

