/Users/johnr/Desktop/IA pdf Downloads/Criteria__P__-_Coding_Project_Upload_all_2022-05-03/SPVCPortal_Panpan/src/main/java/com/mycompany/spvcportal/SortAndSearch.java
 1 /*
 2  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 3  * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 4  */
 5 package com.mycompany.spvcportal;
 6 
 7 import java.util.LinkedList;
 8 
 9 /**
10  *
11  * @author 18916
12  */
13 public class SortAndSearch {
14     
15     public int search(int[] orderIDArray, int keyOrderID){
16         
17         int low = 0;
18         int high = orderIDArray.length - 1;
19         while(low <= high){
20             int mid = (low + high) / 2;
21             if (keyOrderID == orderIDArray[mid]){
22                 return mid;
23             } else if (keyOrderID < orderIDArray[mid]) {
24                 high = mid - 1;
25             } else {
26                 low = mid + 1;
27             }
28         }
29         return - 1;   
30     }
31     
32     public Order[] sortByBuyerName(LinkedList<Order> ordersList){
33         Order order = new Order();
34         Order[] orderArray = new Order[ordersList.size()];
35         
36         for(int k = 0; k < orderArray.length; k++) {
37             orderArray[k] = ordersList.get(k);
38         }
39         
40         for (int i = 0; i < orderArray.length - 1; i++) {
41             for (int j = 0; j < orderArray.length - 1 - i; j++) {
42                 if(orderArray[i].getBuyerName().compareToIgnoreCase(orderArray[i+1].getBuyerName()) > 0){
43                     Order temp = orderArray[i];
44                     orderArray[i] = orderArray[i+1];
45                     orderArray[i+1] = temp;
46                 }
47             }
48         }
49         return orderArray;
50         
51     }
52     
53     public void testMethod() {
54         System.out.println("SortAndSearch");
55     }
56     
57 }
58