Page 469 - computer science (868) class 11
P. 469
61 ob.display1();
62 ob.sort();
63 ob.display2();
64 }//end of main
65 } //end of class
The output of the preceding program is as follows:
ENTER THE SIZE OF ARRAY
5
ENTER THE ARRAY ELEMENTS
7 3 4 79 1
ORIGINAL ARRAY IS :
7 3 4 79 1
THE SORTED IS :
1 3 4 7 79
Variable Description
NAME TYPE DESCRIPTION
ar[] int To store array elements
l int To store array length
i int For-loop variable
val int Acts as temporary variable
p int Stores index of temporary variable
Program 12 Define a class merge sort to accept two arrays and print their sum and then sort them using
merge sort. The data members and member method the defined as follows:
Data Members
Size : store the size of the array
Member Methods
void merge(int[], int, int, int) : to merge two arrays
void sort(int[], int, int) : to sort array using merge sort
int[] add(int[], int[], int) : to input two arrays and find the sum
void printArray() : to print array
Write the main program by specifying the class and defining the methods as given.
1 import java.util.*;
2 class mergesort
3 {
4 void merge(int arr[], int l, int m, int r)
5 {
6 //using mergesort technieque to sort the array
7 //sizes of the 2 subarrays
467
Internal Assessment 467

