Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  
  2. public class question3
  3. {
  4.     public static Integer [] q1 = {52, 14, 68, 99, 120, 54, 28, 96, 14};
  5.     public static Integer [] q2 = {48, 1, 12, 23, 62, 54, 14, 21, 95, 68, 74, 21 };
  6.    
  7.     public static void main(String[]args)
  8.     {
  9.         final int MAX = q1.length, MAX2=q2.length;
  10.         OrderedArrayList list = new OrderedArrayList(MAX);
  11.         for (int i=0; i<MAX;i++)
  12.         {
  13.             list.insert(q1[i]);
  14.         }
  15.         list.display();
  16.         System.out.println("Sequential search of OrderedArrayList[1]:");
  17.         System.out.println("For 84 : "+displayResult(list.seqSearch(84)));
  18.         System.out.println("For 54 : "+displayResult(list.seqSearch(54)));
  19.         System.out.println("For 14 : "+displayResult(list.seqSearch(14)));
  20.         System.out.println("For 250 : "+displayResult(list.seqSearch(250)));
  21.         /*==ANOTHER===============================*/
  22.         OrderedArrayList list2 = new OrderedArrayList(MAX2);
  23.         for (int i=0; i<MAX2;i++)
  24.         {
  25.             list2.insert(q2[i]);
  26.         }
  27.         list2.display();
  28.         System.out.println("Sequential search of OrderedArrayList[2]:");
  29.         System.out.println("For 52 : "+displayResult(list2.seqSearch(52)));
  30.         System.out.println("For 62 : "+displayResult(list2.seqSearch(62)));
  31.         System.out.println("For 95 : "+displayResult(list2.seqSearch(95)));
  32.         System.out.println("For 47 : "+displayResult(list2.seqSearch(47)));
  33.     }
  34.    
  35.     public static String displayResult(int result)
  36.     {
  37.             if (result<0)
  38.                 return "Not Found.";
  39.             else
  40.                 return "Found at index:["+result+"]";
  41.     }
  42. }