fletning af foreningsmængde
Jeg vil flette to Arrays sammenHvis Appcon2 > appCon så kommer sidste element i appCon2 ikke med i fletningen, her er en fejl
Hvis Appcon2 = appCon så kommer sidste element i appCon2 med i fletningen, det fungerer
Hvis Appcon > appCon2 så kommer sidste element i appCon med i fletningen, det er iorden
Koden:
public static AppointmentContainer syncronize() {
AppointmentContainer res = new AppointmentContainer();
int i,j;
i = 0;j = 0;
int tmp,tmp2;
while(i < appCon.size() && j < appCon2.size()) {
if(appCon.getAppoinmentNumber(i) < appCon2.getAppoinmentNumber(j)) {
res.insertItem(appCon.elementAt(i));
i++;
}
else if(appCon.getAppoinmentNumber(i) > appCon2.getAppoinmentNumber(j)) {
res.insertItem(appCon2.elementAt(j));
j++;
}
else {
res.insertItem(appCon.elementAt(i));
res.insertItem(appCon2.elementAt(j));
i++;j++;
}
}
//kopier resten af halen
for( ; j< appCon2.size();j++) {
res.insertItem((Appointment)appCon.elementAt(j));
}
for( ; i < appCon.size();i++) {
res.insertItem((Appointment)appCon.elementAt(i));
}
return res;
}
