Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Java

image

Sequential Searching Object

This repository contains a Java implementation of a simple object-based sequential search algorithm. The project demonstrates how to create a custom object that can be compared using the Comparable interface and how to perform a sequential search on an array of such objects.

Overview

The main focus of this project is to implement a sequential search algorithm for an array of custom objects, called SearchingObject. The SearchingObject class has a single attribute, identity, which is used to compare different instances of the class. The sequentialSearch method is used to find the index of a specific object within an array by comparing their identities.

Usage

To use this code in your project:

  1. Clone your repository
git clone https://github.com/2denata/SequentialSearchingObject.git
cd SequentialSearchingObject
  1. Compile the java code
javac SearchingObject.java
  1. Run the program You can create instances of SearchingObject and use the sequentialSearch method to search for a specific object in an array.
SearchingObject[] objects = new SearchingObject[]{
    new SearchingObject(1),
    new SearchingObject(2),
    new SearchingObject(3)
};

int index = SearchingObject.sequentialSearch(objects, new SearchingObject(2));
System.out.println("Object found at index: " + index);

Code Explanation

Attributes:

  • int identity: The unique identifier for each SearchingObject.

Methods:

  • compareTo(Object t) : Compares two SearchingObject instances based on their identity values.
  • sequentialSearch(Object[] o, Object key) : Performs a sequential search on an array of SearchingObject instances to find the specified key.

Example Usage

The sequentialSearch method loops through an array of SearchingObject instances, comparing each element to the target key. If a match is found, it returns the index; otherwise, it returns -1.

About

Implementation of Linear Search Object algorithm using Comparable interface in Java. Can be use to search any type of data in Java.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages