summary refs log tree commit diff stats
path: root/java/text/ArraySearch.typ
blob: 19e4d7f9750340008e3de2f96d937dfc0b949d3c (plain) (blame)
1
2
3
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: ita
#import "/template.typ": *
#show: A => apply(A)
#set raw(lang: "java-new")
#set par(leading: 0.475em)

#assignment(1)[
  Write a menu-driven program to implement linear and binary search on an object of a custom array class.
]

#scos("ArraySearch")

=== Discussion

#skind[Classes, interfaces and methods used from Java standard library]

- `void java.util.Arrays.sort(double[])`: A static method facilitating in-place sorting of the provided array.
- `java.util.Scanner` Class:
  - Constructor `Scanner(java.io.InputStream)`: Creates a scanner object for scanning values from given input stream.
  - Methods `int nextInt()`, `double nextDouble()`: Scan an integer or `double` value from the the input stream.
- `java.util.function.BiFunction<T, U, V>` Interface:
  - Objects implementing this interface represent functions taking two arguments of types `T` and `U`, returning a value of type `V`.
  - Member method `V apply(T, U)` is used to invoke the underlying function.
- `public static java.io.PrintStream System.out, System.err`: Represents the standard output and error streams.
- `public void java.io.PrintStream.println(String)` and `public void java.io.PrintStream.pri
ength and elements of the array from the user. - `void display()`: Displays the array elements. - `double get(int)`: Returns the value at the specified position. - `void set(int, double)`: Sets the value at the specified position. - `void sort()` Utilizes `Arrays.sort` for in-place sorting. - `int size()`: Returns the size of the array. - The `ArrayOperations` class includes methods for performing searching operations, which takes the array and the value to search in it and returns the position of the element if it found in the array or `-1` instead. - `static int linearSearch(Array, double)`: Performs linear search on the given `Array`. - `static int binarySearch(Array, double)`: Conducts binary search; the array must be sorted before calling. - The `ArraySearch` orchestrates the main program with: - `static void menu()`: Displays the menu. - `static void performSearch(Scanner, Array, BiFunction<Array, Double, Integer>)`: Takes user input, performs the specified search, and displays the result. - `public static void main(String[])`: Implements a menu-driven program for array searching. #signature()