00:00Next question which we are going to do is to swap two numbers
00:03I will give a list of elements in which I will have a list
00:07I will give two indices
00:09First of all, the value of index will tell me which is my first index
00:12and the other index will tell me which is my second index
00:16Like here, my first index is 1 and my second index is 3
00:201 comes here, 5 comes here and 3 comes here
00:23So what do I have to swap these values?
00:27After swap, my list will look like this
00:282, 3, 9, 5 and 6
00:32So what do I have to swap them?
00:34I will use that logic
00:35which I used to swap elements in an integer array
00:39First of all, I have to make a temporary variable
00:42which I will assign to index 1
00:47Then I will change to index 1
00:49I will change to index 1
00:51which is stored in index 2
00:54Then I will change to index 2
00:56I will change to index 2
01:01Then I will change to index 2
01:24So what do I need to make this swap function?
01:26How will this swap function be?
01:27Public, static, void type
01:29This we will be swap
01:30First of all, I will have an array list of integers
01:33How do I pass into an array list of integers?
01:37First I will write my type
01:38which is array list of integers
01:41Then I will write my variable
01:42variable's name. So this is my type in this way, like if I had to write an array in the
01:49function,
01:49then I would write int IntegerArrayArr. So in that way I have written IntegerArrayList List.
01:58With that I will pass my index 1 and index 2.
02:04First of all, I have made a temporary variable.
02:06In the temporary variable, I will assign value List.GetIIndex1
02:12and now if I go to any particular index and change any value,
02:17then what is the simple function of it?
02:19It is a simple function of List.Set.
02:23First of all, I will pass index where I want to change value.
02:27After that, I will pass which new value will come.
02:29So the new value will come, that is List.GetIndex2
02:33value.
02:34What does this line mean?
02:37I have to set a value in the list.
02:39Go to index 1 and store that value in my list,
02:44which is now in index 2.
02:45So the value in index 2 will be copied to index 1.
02:49And the same thing I will do with index 2.
02:54And I will store my temporary variable here.
02:57So I have called the Set function.
02:59If I want to swap in an array list,
03:02two indices values.
03:04Now what will I do?
03:05I will call the swap function.
03:07Swap List index 1 and index 2.
03:13So first of all, I will print my normal list.
03:17After swap, I will print my new list again.
03:23Save and now run.
03:27So first of all, the list is printed.
03:29That is 2, 5, 9, 3, 6.
03:31Then I have swapped values.
03:33So first of all, there is 5.3.
03:34Here is 3.5.
03:36So index 1 and index 3 will be swapped.