Page 585 - ComputerScience_Class_11
P. 585
53 ob.read_list();
54 ob.sort();
55 ob.display();
56 } //end of main
57 } //end of class
The output of the preceding program is as follows:
BlueJ: Terminal Window - Java
Options
ENTER THE SIZE OF THE ARRAY
5
ENTER THE ARRAY ELEMENTS
22
55
33
44
77
THE SORTED ARRAY IS
22
33
44
55
77
Program 12 Design a class Insertion_Sort that inputs an array from the user and sorts it in ascending order
using the insertion sort technique. A main class is created to give details of the constructor
and the member methods.
Data Members
int ar[] : Integer array to store numbers
Member Methods
Insertion_Sort() : A constructor to initialise data members to 0
void input() : To input the array from the user and store it in ar[]
void sort() : To sort ar[] in ascending order
void display() : To display the sorted array
1 import java.util.*;
2 class Insertion_sort
3 {
4 int ar[],n;
5 Scanner sc=new Scanner(System.in);
6 Insertion_sort()
7 {
Internal Assessment 583

