|
|
@@ -56,10 +56,15 @@ public class SortingService {
|
|
|
|
|
|
//若逆序
|
|
|
if(content.get(j)>content.get(j+1)){
|
|
|
+ System.out.println("======former:"+content.get(j)+" later:"+content.get(j+1)+"=======");
|
|
|
//交换位置
|
|
|
Bar tempBar=aBar;
|
|
|
stepContent.set(j,bBar);
|
|
|
stepContent.set(j+1,tempBar);
|
|
|
+ //content中的值也要交换位置
|
|
|
+ int temp=content.get(j+1);
|
|
|
+ content.set(j+1,content.get(j));
|
|
|
+ content.set(j,temp);
|
|
|
ArrayList<Bar> copyExchangeStepContent=BubbleStep.copyContent(stepContent);
|
|
|
onSortingSteps.add(new BubbleStep("onExchange",copyExchangeStepContent));
|
|
|
}
|
|
|
@@ -142,6 +147,10 @@ public class SortingService {
|
|
|
Bar tempBar=aBar;
|
|
|
stepContent.set(j,bBar);
|
|
|
stepContent.set(j+1,tempBar);
|
|
|
+ //content中的值也要交换位置
|
|
|
+ int temp=content.get(j+1);
|
|
|
+ content.set(j+1,content.get(j));
|
|
|
+ content.set(j,temp);
|
|
|
ArrayList<Bar> copyExchangeStepContent=BubbleStep.copyContent(stepContent);
|
|
|
onSortingSteps.add(new BubbleStep("onExchange",copyExchangeStepContent));
|
|
|
}
|
|
|
@@ -349,6 +358,7 @@ public class SortingService {
|
|
|
onSortingStates.add(new InsertionStep("onInsertion",0,currentContent));
|
|
|
currentContent=InsertionStep.copyContent(currentContent);
|
|
|
for(int i=1;i<len;i++){
|
|
|
+ System.out.println("================i: "+i+"============");
|
|
|
currentContent.get(i).setColor("white");
|
|
|
onSortingStates.add(new InsertionStep("onSelect",i,currentContent));
|
|
|
currentContent=InsertionStep.copyContent(currentContent);
|
|
|
@@ -383,7 +393,7 @@ public class SortingService {
|
|
|
currentContent=InsertionStep.copyContent(currentContent);
|
|
|
|
|
|
//移动
|
|
|
- for(int m=i-1;i<=exchangeIndex;i--){
|
|
|
+ for(int m=i-1;m>=exchangeIndex;m--){
|
|
|
content.set(m+1,content.get(m));
|
|
|
}
|
|
|
content.set(exchangeIndex,value);
|