Coding Insertion Operation in Array in Data Structures in C
language
ByAnonymous–
Today we 're going to talk about insertion. If you remember , we had talked in great detail About
what ? We 'd talked about some array operations in detail. And what I 'll do here is , I hope you
have accessed this array operations PDF that I 've given you. This is a course for data structures
I do n't want to teach you how to print the elements of an array. So here I 'll make an int size=4;
that shows that we are using 4 elements. And that it has the capacity to store 100 elements. If I
want , in the future I can add more elements. If there is no space in your array, then what can you
do? If your whole array is full; when your size is > or = to the capacity , Then I ca n't take any
more in it. If the capacity of your tank is 100 litres, and there are already 100 litres then the 101st
litre can't fit in it ; no matter how much it tries.
When there 's no space or capacity you 'll have to return -1. Assume that this is an array of
7,8,12,27 and 88. And ahead of this , there is a lot of space. So for that, a for loop will be
working. So I 'm taking -1 as a representation because if you return. Then your insertion was n't
successful. Okay ? Now I 'll do this. The insertion was. n't. successful here. Now if it does n't get
returned , what does it mean ? So I want that index 4 should go ahead. Because there 's space in
the array. If there was n't space then it would return it. So 88 will move ahead. I 'm starting from
i=size -1. My size is 5 i. 'll have to do arr (i+1 ) =arr (i ). And along with that ; I 'll write arr here and
either return the index or return 1. 1 for success. It 's done ; we 've successfully done an
insertion in your array. I hope that this course must be helpful for you. So many people have
accessed the playlist and I 'm so happy to see that. And many of you have downloaded the
notes. So here you guys can do one thing , There 's a quiz for you guys and that is ; you have to
modify this code Such that you should be able to find out whether the insertion was successful
or not. If the insertion is successful, You will print the new , modified array. Otherwise, you will
say that 'insertion failed' and that will be enough.
language
ByAnonymous–
Today we 're going to talk about insertion. If you remember , we had talked in great detail About
what ? We 'd talked about some array operations in detail. And what I 'll do here is , I hope you
have accessed this array operations PDF that I 've given you. This is a course for data structures
I do n't want to teach you how to print the elements of an array. So here I 'll make an int size=4;
that shows that we are using 4 elements. And that it has the capacity to store 100 elements. If I
want , in the future I can add more elements. If there is no space in your array, then what can you
do? If your whole array is full; when your size is > or = to the capacity , Then I ca n't take any
more in it. If the capacity of your tank is 100 litres, and there are already 100 litres then the 101st
litre can't fit in it ; no matter how much it tries.
When there 's no space or capacity you 'll have to return -1. Assume that this is an array of
7,8,12,27 and 88. And ahead of this , there is a lot of space. So for that, a for loop will be
working. So I 'm taking -1 as a representation because if you return. Then your insertion was n't
successful. Okay ? Now I 'll do this. The insertion was. n't. successful here. Now if it does n't get
returned , what does it mean ? So I want that index 4 should go ahead. Because there 's space in
the array. If there was n't space then it would return it. So 88 will move ahead. I 'm starting from
i=size -1. My size is 5 i. 'll have to do arr (i+1 ) =arr (i ). And along with that ; I 'll write arr here and
either return the index or return 1. 1 for success. It 's done ; we 've successfully done an
insertion in your array. I hope that this course must be helpful for you. So many people have
accessed the playlist and I 'm so happy to see that. And many of you have downloaded the
notes. So here you guys can do one thing , There 's a quiz for you guys and that is ; you have to
modify this code Such that you should be able to find out whether the insertion was successful
or not. If the insertion is successful, You will print the new , modified array. Otherwise, you will
say that 'insertion failed' and that will be enough.