﻿1
00:00:00,440 --> 00:00:03,090
‫Now we're going to create our keys function.

2
00:00:03,110 --> 00:00:10,520
‫I'll bring up an address space with a few items in it, and the keys function is going to return a vector

3
00:00:10,520 --> 00:00:15,380
‫of strings, which is going to be the keys and the hash table.

4
00:00:15,740 --> 00:00:20,360
‫So we'll create that vector like this, we'll call it all keys.

5
00:00:20,540 --> 00:00:25,070
‫And in order to do this, we're going to need two different loops.

6
00:00:25,250 --> 00:00:29,930
‫First, we need one that's going to iterate through the array.

7
00:00:30,170 --> 00:00:37,400
‫And because we know exactly how many items are in the array, we'll do this with a four loop and then

8
00:00:37,400 --> 00:00:43,280
‫we'll need a separate loop to loop through the length list, like the one we have at the index of six.

9
00:00:43,610 --> 00:00:48,060
‫Now to loop through that length list, we'll need a variable that we call temp.

10
00:00:48,080 --> 00:00:56,300
‫We'll create that like this and we'll set it equal to data map at the index of I the I from the for

11
00:00:56,300 --> 00:00:56,870
‫loop.

12
00:00:57,050 --> 00:01:02,600
‫And the loop that goes inside of this for loop is going to be a while loop.

13
00:01:02,810 --> 00:01:08,630
‫And the reason for that is because we don't know how long the linked list is.

14
00:01:08,870 --> 00:01:12,620
‫So we're just going to run this until we get to the end.

15
00:01:13,040 --> 00:01:17,150
‫And then inside the wild loop will say all keys.

16
00:01:17,150 --> 00:01:24,870
‫That is the vector push back that allows it to the end of the vector temp key.

17
00:01:24,890 --> 00:01:27,470
‫So right now temp key is nails.

18
00:01:27,470 --> 00:01:30,530
‫So we're adding nails to the vector.

19
00:01:30,920 --> 00:01:39,230
‫And to move temp forward in the length list, we'll say temp equals temp next and then we'll add tile

20
00:01:39,560 --> 00:01:40,580
‫and lumber.

21
00:01:41,210 --> 00:01:48,890
‫And now the only thing left to do is to return all keys, which returns that vector.

22
00:01:49,430 --> 00:01:52,640
‫So we'll look at this code in a moment in VTS code.

23
00:01:52,640 --> 00:01:59,720
‫And when we do, we'll create a hash table that looks like this, except we will also add these two

24
00:01:59,720 --> 00:02:02,170
‫items to make it a little bit more interesting.

25
00:02:02,180 --> 00:02:07,820
‫And then we'll run the keys function and we'll expect it to return this vector.

26
00:02:08,180 --> 00:02:12,110
‫So now let's flip over to VS code and take a look at this.

27
00:02:12,710 --> 00:02:17,780
‫So there is our keys member function there and I'm going to scroll up.

28
00:02:18,230 --> 00:02:24,260
‫So this line creates our hash table and these lines create our five key value pairs.

29
00:02:24,530 --> 00:02:27,410
‫And then with this line we'll run a print table.

30
00:02:27,680 --> 00:02:29,060
‫So I'll run this.

31
00:02:29,510 --> 00:02:32,120
‫And that is our hash table there.

32
00:02:32,480 --> 00:02:40,280
‫So now I'm going to come up and replace this line that says print table with these lines.

33
00:02:40,610 --> 00:02:47,660
‫And with this line here, we're creating a vector of strings called my keys, and we're setting an equal

34
00:02:47,660 --> 00:02:50,120
‫to my hash table keys.

35
00:02:50,120 --> 00:02:57,830
‫And remember, that function returns a vector of strings, and then this for loop will print out all

36
00:02:57,830 --> 00:03:00,170
‫of those keys in that vector.

37
00:03:00,680 --> 00:03:08,570
‫And now I'll run this and you can see we get all of our keys paint, bolts, nails, tile and lumber.

38
00:03:09,200 --> 00:03:13,160
‫And that is our function for keys.

