Practical 8
Practical 8
Year 2
Lab Exercise 8
Objectives:
The bubble sort algorithm allows you to sort data. The following code shows how to sort an integer
array using bubble sort.
(a) Write a main function to call the bubbleSort() to sort an array of 10 elements
(b) Rewrite the above class using generics so that the solution works for any kind of data.
(c) Rewrite the main function that uses the generic sort class to sort arrays containing
a. Float array
b. Double array
(d) Rewrite the bubbleSort() as a generic method and use it in the code as a generic method
Exercise 2
Implement a generic method called print which can print any value type. The message will be string.
Below is a version of the print() message that works only for integers.
e.g. of usage