﻿1
00:00:00,410 --> 00:00:05,720
‫So in this video, we're going to rewrite our code for delete last.

2
00:00:06,080 --> 00:00:08,170
‫So I'm going to bring up our code here.

3
00:00:08,180 --> 00:00:13,190
‫And the reason I'm going to change some things here is because having an if statement for the length

4
00:00:13,190 --> 00:00:20,750
‫being equal to zero here and having the same thing down here is not as readable as it could be.

5
00:00:20,780 --> 00:00:24,890
‫Now, remember, this one happens after we decrement the length.

6
00:00:24,920 --> 00:00:30,860
‫The length was one becomes zero, and then we run this if statement.

7
00:00:31,370 --> 00:00:37,850
‫So what I'm going to start out with doing is just taking these lines and moving them over to the side.

8
00:00:38,000 --> 00:00:42,710
‫Then we're going to take this if statement and move it up.

9
00:00:42,710 --> 00:00:47,180
‫And when we do, we're going to change this 0 to 1.

10
00:00:47,420 --> 00:00:54,800
‫And the only new code will add here is we'll say else and we'll move these lines into the statement.

11
00:00:54,800 --> 00:00:57,770
‫And now we have rewritten this code.

12
00:00:57,950 --> 00:01:05,060
‫And the thing that makes this more readable is because if length is equal to zero is here, length is

13
00:01:05,060 --> 00:01:09,530
‫equal to one is here, and then two or more items is here.

14
00:01:09,920 --> 00:01:15,920
‫So you might be asking yourself, why didn't I just write it this way in the last video?

15
00:01:16,250 --> 00:01:21,260
‫And the reason for that is this edge case where the length is equal to one.

16
00:01:21,470 --> 00:01:26,930
‫It's hard to explain why this is an edge case when you write the code like this.

17
00:01:27,200 --> 00:01:33,350
‫This code is a lot more readable, but it is more difficult to explain that concept.

18
00:01:33,530 --> 00:01:39,410
‫But the way I wrote the code and the other video, it's very easy to explain why this is an edge case,

19
00:01:39,410 --> 00:01:42,050
‫and I didn't want to just gloss over that.

20
00:01:42,320 --> 00:01:48,710
‫So we're going to have this same edge case for one item when we get to the delete first function.

21
00:01:48,710 --> 00:01:55,700
‫And when we do, I'm going to write it like this since we have already covered the concept and we'll

22
00:01:55,700 --> 00:02:02,960
‫see this again in doubly length less with the delete last and delete first functions in that section.

23
00:02:03,200 --> 00:02:07,580
‫And that is our rewrite for delete last.

