1
00:00:00,830 --> 00:00:01,160
OK.

2
00:00:01,190 --> 00:00:05,240
Welcome back to another lecture in today's lecture is going to be pretty short, it's actually just

3
00:00:05,240 --> 00:00:11,750
a sorting challenge that I have for you, and I know we haven't talked about sorting, but we are going

4
00:00:11,750 --> 00:00:12,840
to talk about sorting.

5
00:00:12,860 --> 00:00:21,140
And what I want you to do first is challenge yourself and see if you can actually come up with a sorting

6
00:00:21,140 --> 00:00:22,460
algorithm on your own.

7
00:00:22,460 --> 00:00:24,770
And so that is what I'm going to challenge you to do today.

8
00:00:25,340 --> 00:00:26,630
So let's get into it.

9
00:00:28,100 --> 00:00:36,110
So what I want you to do is try to make a program that takes in five integers and five.

10
00:00:36,140 --> 00:00:42,140
It can really be any integers if you want, but just to make it simple so you can like trace it on paper

11
00:00:42,140 --> 00:00:42,980
if you need to.

12
00:00:43,340 --> 00:00:45,770
Why don't we go ahead and start out with just five integers?

13
00:00:46,520 --> 00:00:51,920
So taking these five integers from the user, read them into either an array or vector.

14
00:00:51,930 --> 00:00:57,770
It's your choice, and then your program should sort the numbers in that container.

15
00:00:57,770 --> 00:01:01,010
So the array or vector before then printing them out.

16
00:01:01,070 --> 00:01:06,920
Here is a sample running of the program with the input and output, so you notice that it just repeatedly

17
00:01:06,920 --> 00:01:08,510
five times asked for a number.

18
00:01:08,960 --> 00:01:14,570
So the numbers are being read into an array of vector in this order for one nine three two.

19
00:01:15,800 --> 00:01:20,900
Yet the numbers then get printed out one two three four nine, which is in sorted order.

20
00:01:22,850 --> 00:01:27,170
So there's a few tips I can give you for this.

21
00:01:27,470 --> 00:01:31,580
I won't give you a ton and this might be really, really hard.

22
00:01:32,000 --> 00:01:41,780
So if you're not able to figure something out, I don't expect you to be able to necessarily do it in

23
00:01:41,780 --> 00:01:44,030
a short amount of time or even do it at all.

24
00:01:44,330 --> 00:01:49,150
It's just to kind of try and challenge yourself to think of how what would I do to sort these things?

25
00:01:49,160 --> 00:01:54,680
You do have all the tools necessary to sort a vector or an array.

26
00:01:55,010 --> 00:02:00,290
It's just kind of a little tricky to think about how it works, but I'm going to give you some tips.

27
00:02:00,290 --> 00:02:05,550
So a big thing is swapping positions of the array or vector.

28
00:02:05,570 --> 00:02:07,130
It's definitely going to be necessary.

29
00:02:08,250 --> 00:02:09,660
So how do you do that?

30
00:02:10,960 --> 00:02:18,360
So you can do something like, you know, let's say you have some vector like my event, I.

31
00:02:19,150 --> 00:02:22,240
And then you say, you know, my vector, I got my vector plus one.

32
00:02:22,240 --> 00:02:27,360
So all this is saying is that whatever position I'm looking at right now.

33
00:02:28,810 --> 00:02:31,570
I want to take whatever is right past it.

34
00:02:31,840 --> 00:02:33,670
And I want to.

35
00:02:34,810 --> 00:02:40,180
Copy that into, you know, the one I'm currently on, and then this right here is kind of doing the

36
00:02:40,180 --> 00:02:46,180
opposite, so you could, you know, do the vice versa, but you should really think about whether this

37
00:02:46,780 --> 00:02:51,280
would work if you just had these two lines in a row.

38
00:02:52,620 --> 00:02:54,330
Would that really swamp them?

39
00:02:55,050 --> 00:03:02,100
So what you should probably do if this seems confusing to you is draw your a vector on a piece of paper

40
00:03:02,100 --> 00:03:05,600
with an example and then one line at a time.

41
00:03:05,610 --> 00:03:13,650
So let's try and do this line first and then do this line afterwards and see if you are able to successfully

42
00:03:13,650 --> 00:03:14,190
swat them.

43
00:03:14,190 --> 00:03:20,440
You most likely are only able to update this line, but not vice versa.

44
00:03:20,460 --> 00:03:22,890
So that is a tip that I have for you.

45
00:03:22,920 --> 00:03:26,410
Another tip is to use loops.

46
00:03:26,430 --> 00:03:34,140
Of course, you're going to want to go through your array or vector, and you're going to have to move

47
00:03:34,140 --> 00:03:35,640
things around, right?

48
00:03:35,670 --> 00:03:37,170
That's what the swapping is.

49
00:03:37,710 --> 00:03:45,840
And you know, that movement, while swapping is what can really get you a sorted array or assorted

50
00:03:46,110 --> 00:03:46,740
vector.

51
00:03:48,450 --> 00:03:50,880
So think about this a lot.

52
00:03:51,090 --> 00:03:57,000
I'm not going to give any other tips or hints, but I think with what I've told you so far, you can

53
00:03:57,000 --> 00:03:58,080
figure it out.

54
00:03:58,350 --> 00:04:03,540
You do not have to solve this like in just a few minutes.

55
00:04:03,540 --> 00:04:05,610
It can take you as long as you need.

56
00:04:05,610 --> 00:04:10,040
It might take some of you only, you know, five to 10 minutes.

57
00:04:10,050 --> 00:04:13,340
It might take other people several hours.

58
00:04:13,350 --> 00:04:20,010
It might take other people a full day of work or two days of work, you know, depending how much time

59
00:04:20,010 --> 00:04:22,400
you have, if it's very confusing.

60
00:04:22,410 --> 00:04:28,890
But just take all the time you need, but really think about it, drawing things on paper is your friend,

61
00:04:29,010 --> 00:04:38,100
you know, draw out the little boxes for the positions of the array and then have a little table, maybe

62
00:04:38,100 --> 00:04:41,730
where you record what your variables are.

63
00:04:41,940 --> 00:04:45,630
For example, if I is changing.

64
00:04:46,260 --> 00:04:49,620
Say what is each time a loop iterate?

65
00:04:49,680 --> 00:04:50,640
So each loop.

66
00:04:51,890 --> 00:04:53,990
Take, I am big, what is I?

67
00:04:54,290 --> 00:04:56,690
Oh, what is my vector I?

68
00:04:57,470 --> 00:04:58,520
What is my vector?

69
00:04:58,550 --> 00:05:01,430
I plus one or my vector I minus one?

70
00:05:01,820 --> 00:05:04,160
I'm not saying that you have to use I plus one.

71
00:05:04,580 --> 00:05:06,050
You can also use a minus one.

72
00:05:06,440 --> 00:05:10,340
Just make sure you're recording and keeping track of those variables.

73
00:05:10,340 --> 00:05:12,500
So you're noticing how it's changing.

74
00:05:12,500 --> 00:05:18,740
And when you write your code, you can trace it on paper and draw out the array and show how the array

75
00:05:18,740 --> 00:05:19,160
changes.

76
00:05:19,160 --> 00:05:25,700
Each time you want to redraw your array, every single loop iteration to see how it's being sorted step

77
00:05:25,700 --> 00:05:29,270
by step or if something's wrong, that's a good way to debug it.

78
00:05:30,050 --> 00:05:34,100
Also, remember that see out statements are your friend as well.

79
00:05:34,640 --> 00:05:41,960
Printing out stuff in the loop that you're confused about, like you're not sure how my vector is changing,

80
00:05:41,970 --> 00:05:43,590
then print it out every time.

81
00:05:43,610 --> 00:05:47,660
Throw out it, throw in a little see out statement there so you can see how it's changing.

82
00:05:48,050 --> 00:05:48,350
All right.

83
00:05:49,280 --> 00:05:51,590
So with that, I will let you go.

84
00:05:51,590 --> 00:05:58,310
And in the next video and the next subsequent videos, I'm going to show you a few different sorting

85
00:05:58,310 --> 00:06:05,010
algorithms and just in general, how we can think about sorting things in an efficient manner.

86
00:06:05,270 --> 00:06:08,480
So do not look up any answers.

87
00:06:08,480 --> 00:06:10,310
OK, do not look up sorting algorithms.

88
00:06:10,310 --> 00:06:12,860
Try and come up with your own sorting algorithm.

89
00:06:12,890 --> 00:06:13,220
All right.

90
00:06:13,940 --> 00:06:15,770
And with that, I'll see you in the next lecture.
