00:01
Hello students, we need to write a program to perform selection sort in sorting the elements of array in assigning order.
00:08
Let's say if our input is our 5, 4, 1, 3, 2.
00:14
So what we need output after sorting is 1, 2, 3, 4 and 5 in ascending order, right? so basically output is in a standing order, right? so if i write for selection sort, selection sort, so basically if i clear two points here, the selection sort works by taking the smallest, taking the smallest element, element in an unsorted, in an unsorted array and bringing and bringing, and bringing.
00:58
Bringing it in the front, bringing it to the front.
01:06
Right.
01:07
In the second case, if i write here, you will go through each item, you will go through each item.
01:18
You will go through each item from left to right until you find the smallest one.
01:24
From left to right until you find a smallest one.
01:33
So let's start our coding part to sort that array, right? so basically we are writing our c programming code here.
01:43
C programming code here.
01:45
We are using the language as c programming.
01:48
Right.
01:50
So this is hashtag includehtiu dot s.
01:56
So we are taking stdi -do .h library and we are making our inta main function because we want to return, right, int data type.
02:08
So basically all the data types are in.
02:10
So inta main function, let's start our programming part.
02:14
Right.
02:14
So firstly, we are declaring our array.
02:18
B5, which is our array, must be declared.
02:21
B5 having the elements, if i write all the elements, elements are 5 .4.
02:26
1412, 5, 4, 1, 3, 2.
02:31
So definitely we all know number of elements are n n is equal to 5, we all know that.
02:39
So basically first we take int, i comma j, we are declaring and we are declaring a variable which is position and we are declaring a variable which we need to swap.
02:52
So now what we are doing is 4, 4, 4, is equal to 0, i is less than n minus 1, i plus plus, i plus, and this is equivalent to position is equals to i, right? so basically if i write for this position is equals to i, now what we are doing is we are making our four loop again, j is equal to i...