COMP2247 - Algorithms and Data Structures

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

Sorting and Searching Algorithms SelectionSort Program BinarySearch Program QuickSort Program HardwareStore Program HardwareStore Comparable Objects Program



HardwareStore Sort and Search Comparable Objects Program


Description

This program uses the selection sort, quick sort, and sequential search algorithms to conduct sorting and searching on an array of Comparable Inventory objects.

Associated Concepts:

Comparable objects

Selection Sort, Quick Sort, and Sequential Search on an array of Comparable objects.

Algorithm:

Inventory class:

Make objects of Inventory class as Comparable objects.

It implements Comparable interface.

Override compareTo() method.

SortingSearchingComparbleObjects class:

In terms of algorithms, the method definitions of Selection Sort, Quick Sort, and Sequential Search are the same as the integer versions.

Since the objects in the array are Comparable objects, two objects can be compared directly using the object's compareTo() method.

Client main method:

Call the methods defined in SortingSearchingComparbleObjects.java to test them.

Source Code