Okay, this might be 5 o' clock in the morning talking, but I cannot seem to get this right. It does not sort the numbers at all. Thank you for any help.
The program is made up of three classes: A which has the sort, Test which test it and Interval which is basically a simple class used to hold two dates.
Please let me know if it won't compile, I just took out the important bits of my program and pasted them here.
package abc;
import java.util.*;
publicclass Interval {
public Date start_date, end_date;
public Interval(Date start_date, Date end_date)
throws IllegalArgumentException{
if(start_date.before(end_date)) {
this.start_date=start_date;
this.end_date=end_date;
} else {
thrownew IllegalArgumentException("Start date must be before end date");
}
}
}
Sorting implies moving things around in the array. I don't see you doing that.
Also, I don't quite know what you are trying to do with a "binary insertion sort", unless you are trying to optimize the insert with a binary search for the proper place.
Sorting implies moving things around in the array. I don't see you doing that.
The reason I chose insertion sort, is because it allows me to sort elements one by one, because basically my program will not be getting all the data at once. i.e: I get one date, it then gets inserted, next time I run the program (obviously there are files being used to serialize data) another date is added, so on and so forth. If I was getting all the data at once I would have used a much more efficient sorting technique.
EDIT: I just read the linked article, this is what I am doing:
Lists can be sorted as you receive new elements.
Also, I don't quite know what you are trying to do with a "binary insertion sort", unless you are trying to optimize the insert with a binary search for the proper place.
Yes, that is exactly it, a quick Google search would have given you the answer as well.
By the way, if you plan to sort something you should create a separate method specifically for it.
I will try that, but do you have any idea on why my code is not working?
Yes, that is exactly it, a quick Google search would have given you the answer as well.
Get some sleep and try again, because you are being rather rude. I've done more googling on sorting methods than you have.
It should be fairly obvious that I was so tired that I missed the connection, seeing as I wrote it down in my response but still missed it. Maybe I was tired, no? You will also notice that the FAQ I linked for you specifically recommends using a binary search to find the insertion point.
but do you have any idea on why my code is not working?
Sorting implies moving things around in the array. I don't see you doing that.
Try actually moving some elements in your array.
I'm not at a PC I can use to play with your code ATM, but I'll see if I can get a chance later.