OrderSet.java
. OrderSet
, it contains a list of
integers and the list is in ascending order. public class OrderSet extends Vector { // the list of integers are in ascending order // insert an integer x to the correct position of the list of integers // so that the list of the integers is still in ascending order public void insert(int x) { // your codes here } // return the integer at the specify position of the list public int getInteger(int index) { // your codes here } }
//your codes here
. java OrderSetTest
.
The output of the program ispublic class OrderSetTest { public static void main(String[] args) { OrderSet s = new OrderSet(); s.insert(10); s.insert(5); s.insert(15); System.out.println(s); s.insert(7); System.out.println(s); s.insert(-5); System.out.println(s); s.insert(30); System.out.println(s); s.insert(28); System.out.println(s); s.insert(0); System.out.println(s); int num; num = s.getInteger(3); System.out.println(num); } }
[5, 10, 15] [5, 7, 10, 15] [-5, 5, 7, 10, 15] [-5, 5, 7, 10, 15, 30] [-5, 5, 7, 10, 15, 28, 30] [-5, 0, 5, 7, 10, 15, 28, 30] 7
Integer
class.Vector
class.