Page 468 - computer science (868) class 11
P. 468
27 System.out.print(ar[i]+ " ");
28 }
29 System.out.println();
30 }
31
32 void sort() //sort the given array
33 {
34 int val, p;
35 for(int i=1;i<n;i++)
36 {
37 val=ar[i];
38 p=i-1;
39 while(p>=0 && ar[p]>val)
40 {
41 ar[p+1]=ar[p];
42 p--;
43 }
44 ar[p+1]=val;
45 }
46 }
47
48 void display2() //display the sorted array
49 {
50 System.out.println("THE SORTED IS :");
51 for(int i=0;i<n;i++)
52 {
53 System.out.print(ar[i]+ " ");
54 }
55 }
56
57 public static void main()
58 {
59 Insertion_sort ob=new Insertion_sort();
60 ob.accept();
466466 Touchpad Computer Science-XI

