sorter.java

来自「这是Java的模式编程」· Java 代码 · 共 34 行

JAVA
34
字号
package Strategy;
import java.io.*;
public class Sorter
{
	private SortStrategy sortStrategy;
	
	public String[] sort(Comparable[] a)
	{
		sortStrategy.sort(a);
		return sortStrategy.getBack();
	}
	public void setStrategy(String sortStrategy)
	{
		if(sortStrategy.compareTo("BinSort") == 0)
		    this.sortStrategy = new BinSort();
		if(sortStrategy.compareTo("BubbleSort") == 0)
			this.sortStrategy = new BubbleSort();
		if(sortStrategy.compareTo("QuickSort") == 0)
			this.sortStrategy = new QuickSort();
		if(sortStrategy.compareTo("MergeSort") == 0)
			this.sortStrategy = new Mergesort();
		if(sortStrategy.compareTo("HeapSort") == 0)
			this.sortStrategy = new HeapSort();
		if(sortStrategy.compareTo("ShellSort") == 0)
			this.sortStrategy = new ShellSort();
		if(sortStrategy.compareTo("RankSort") == 0)
			this.sortStrategy = new RankSort();
		if(sortStrategy.compareTo("SelectionSort") == 0)
			this.sortStrategy = new SelectionSort();
		
	}


}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?