HW 5: Order Set

Submit

You should submit one file only : OrderSet.java.
You are not allowed to use the java build in sort method in Collection class. If you do that, no point will be given.

Description of the HW.

You are going to write a class OrderSet, it contains a list of integers and the list is in ascending order.
Here is part of the code.
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
    }
}
You should fill your codes under //your codes here.
You don't have to add new methods or new variable names, or insert new codes somewhere else. (You can if you want to.)

Test

After you finish, you can test your program by the following program.
Compile the following program and your program. Run it by java OrderSetTest.
public 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);
    }
}
The output of the program is
[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

Preparation

This HW is a very easy homework. It takes me less than 20 lines to finish it. You should just add about 10 line to the code I given.
Before you start, you should know