hi everybody,
[there were few topics on this in the forum, but nothing could solve my problem yet. so, please instruct me]
I have to sort a vector which contains objects, where each object represents, different data types of values,
ex: {obj1, obj2, obj3, ....}
obj1---->{String name, int ID, String[] departments}
i have to sort this vector at three times, once by name, then by ID and then by departments.
Leaving name and department , first i want to sort the ID of each object and then re-arrange the order of objects in the array according to new order.
what i did was, copied the vector all objects' ID values to an integer array then i sorted it using selection sort. but now i want to re-arrange the vector, but i still can't. please guide.
here is the sort i did, and the
int[] ID = new int[mintomaxID.size()];
for(int i=0;i<mintomaxID.size();i++)
{
ObjectStore_initialData obj_id = (ObjectStore_initialData)mintomaxID.elementAt(i);
ID[i] = obj_id.getID();
}
System.out.println("Before sorting array");
for(int i=0;i<ID.length;i++)
{
System.out.println(ID);
}
System.out.println();
int i, j, m, mi;
for (i = 0; i < ID.length - 1; i++) {
/* find the minimum */
mi = i;
for (j = i+1; j < ID.length; j++) {
if (ID[j] < ID[mi]) {
mi = j;
}
}
m = ID[mi];
/* move elements to the right */
for (j = mi; j > i; j--) {
ID[j] = ID[j-1];
}
ID[i] = m;
}
System.out.println("After sorting array");
for(int y=0;y<ID.length;y++)
{
System.out.println(ID[y]);
}
//*****here is where i need to re-arrange the entire vector by ID.
****/
I do understand this is some sort of database sort type of a question. but there's no database. it's simply i just want to sort the vector.
Thank you.