36 - INSERTION OF AN ELEMENT INTO AN ARRAY AT SPECIFIC POSITION - C PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome to our channel so in the previous session we have learned the one-dimensional add it so how could they clear a one-dimensional edit and how to access the elements of one is one dimensional array and how to read the elements into the ornamental area and how to display the elements of an array and in this session let us have a look on various operations that can be done on other elements so here we can perform different operations on the ad addicts in that the major operations are insertion deletion sorting searching so these are the major operations that can be done on arrangements that means we can insert the element into an array at a particular position and similarly we can delete the element from the array from the given position and we can sort the elements of array that makes in an ascending order or a descending order so we can arrange the elements in an array and then searching that means we have to find the existence of an element in the given atom so let us have a look on these operations one by one first one insertion of an element into an egg so first we have to take one direction edit we have to declare one dimensional array and we have to take the size of an array and we have to read the all the elements into an array and then we need to add one element into an array at a particular position and so insertion of element at a specified position insertion of an element specific into specified position in an a so first let us have a look on example so that we can break the code so here what the user have to give the input so what are the inputs that the user must view that means first elements of an array and then the user have to specify the position where he wants to insert an element and the element which is to be inserted the element which is to be inserted so first one is elements of an array then the position where the new element to be inserted and the third one is which element is to be inserted see let us take an example let it be the elements of an array are 10 20 30 40 50 so these are all the values and 0 1 2 3 4 these are indexes in this of elements next element representations are a of 0 F 1 you have to a of 3 yep let it be an egg here an array is fork so yeah of fine because these are 5 elements so 0 1 2 3 & 4 5 elements so here the index starts from 0 so when I get it the index values from 0 to 4 and the values are 10 20 30 40 and 50 and the element representation is G of 0 F 1 you have to any of the end F 4 here the end value let it be n is a size of air a is equal to 5 because there are five elements so n is equal to 5 here our question is our problem is we have to insert a new element at a specific position that phase we have to add one element to the array that means L will become L plus 1 after insertion gen will become n plus 1 after insertion because now there are 5 elements 10 20 30 40 50 and if you add one more element then the index value will be total 6 that means 0 to 5 there will be another element that is 5th index 1 and here the position if you want to insert the element in third position and the element is 35c the user wants to insert the element active file in the position three so what we have to do we have to push it not disturb all these three because zero one two we should not disturb from these elements just we have to move these elements to the right post element that means third element must be moved to the fourth element fourth element must be moved to the fifth element so 14 will be moved in the fourth position 50 will be moving to the fifth position and this will be a fun of your restroom so here we have to insert the element new element in the position three so three is a position and from that position we have to shift all the elements towards the immediate right position that that means simply we can write in generalize thing let index maybe I so here yeh off index plus one is equal to a of index so in general form it will combine these things so if index is 3 yeah 4 is equal to a of 3 that means we are assigning the value of y of 3 to the position you have 4 so you have 3 value for T will be assigned to 4 and then again for will be assigned to fight so here we need to shift all the elements towards the right from the position itself so further we can write we can start moving from rightmost corner right first shift the last element to the noon last element that means Yin the element 2 enters one yeah - element 2 yeah that means first we can write so yes element 2 L plus 1 here minus 1 element 2 y n the N minus 2 element to the N minus 1 so on up to position so position we have to insert no then insert this petty file at the position so yeah of position is equal to write the element plane so let us write a program so that you can clearly understood so hope you understood this one so if you want to insert an element at a particular position from the last element we have to shift to the towards the right positions so M element nth element that means in the present era the last element must be moved to the next position that means n plus 1 element so the N minus 1 element must be moved to the N here minus 2 element must be moved to the N minus 1 element that must be done until it reaches the position which given by the user and we should not disturb all the elements before the position hope you understood so we can write a program so that you can clearly see so hash include' so include the header file mailing function and declare an array each array of five that means maximum this array can be stole storing maximum of five elements so then array the array elements so for reading a starting without shade so in the previous session we have seen the logic for reading an elephants into an area that is scanner so we have to use an iterative statement fun reading all the elements into another so I is equal to zero so index always starts from zero so we need to insert the elements from 0th index system and less than five because from zero we are counting is the indexes for properly five elements will be there so less than 5 I plus plus scanner percentage D and resent array of I so here we have computed reading all the elements into an array now we have to get the position where the value should be inserted so write the scanner field for reading the position percentage D ampersand position so within two variables that is position and element so then they event should be either the where the value to be inserted and the back which way I have to be inserted we have to be inserted which values to be inserted so position suppose we have to take the input so again write the scanner and take the input and image so we have to insert this element into the position so after taking the inputs of position and element so now we need to shift the nth element to and one and n minus L went to n and so so that until it reaches to the position so we should not disturb any element before the position indexes so here we can write and iterative statement that is equal to four so because last statement is fourth element last segment is the first and fourth element so I is equal to four we have to repeat the process until it reaches through position ie less than or equal to position and then we need to decrement we need to determine that so we have to repeat that we have to shift or we have to assign the N value to the n plus one position so array of I plus one is equal to area of I close of this so this will repeat until the I index value reaches to the position so immediately after reaching the position control will come out from the loop now we have to insert or we have to SI the element at the position position is equal to in it and now display the elements of an array of the display screen further also we have to use an iterative statements so right on here for I is equal to zero I less than or equal to five because previously the number of elements are five the index values are from zero to four after inserting an element the index values will be 0 to 5 total six elements so is not equal to 5 I press press printf percent HD and off this instant program so here we can take the slice as young if you take the sizes young we can replace it with en elements here we can write n minus 1 and then very very you same here we have to write n plus 1 because so it's also same that is not equal to again will be the same thing so like this we can insert an element into n array at a particular position so this is one operation that can be done on one dimensional arrays hope you understood this and
Info
Channel: Sundeep Saradhi Kanthety
Views: 163,714
Rating: 4.7553563 out of 5
Keywords: sundeep, saradhi, kanthety, cp, c language, c programming, computer programming, one dimensional arrays, insertion into array, operations on arrays, position, element, index values, array, integer arrays, numerical arrays, specific position, insertion at specified position
Id: 5y59bLxe-PY
Channel Id: undefined
Length: 15min 50sec (950 seconds)
Published: Thu Sep 21 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.