Page 294 - Computer science 868 Class 12
P. 294

34               a[pos-1] = x;
                35           }

                36           void display()
                37           {
                38               for(int i = 0; i < n; i++)

                39               {

                40                   System.out.print(a[i]+",");
                41               }
                42               System.out.print(a[n]);

                43           }
                44            public static void main(String[] args)

                45           {
                46              Insert_Array ob= new Insert_Array();

                47              ob.input();
                48              System.out.println("Before Insertion");

                49              ob.display();
                50              ob.insert();

                51              System.out.println("\nAfter Insertion");
                52              ob.display();

                53           }
                54       }

              The output of the preceding program is as follows:
              Enter no. of elements you want in array:5
              Enter all the elements:
              1
              2
              4
              5
              6
              Enter the position where you want to insert element:3
              Enter the element you want to insert:3
              Before Insertion
              1,2,4,5,6,0
              After Insertion
              1,2,3,4,5,6


              9.3.4 Deletion of an Element
              It is a process of removing an element from an array. The process involves the following steps:

              a.  First, take the position to be deleted which should be within the range of the array size.


                292292  Touchpad Computer Science-XII
   289   290   291   292   293   294   295   296   297   298   299