반응형

quickSort

package algorithm;

public class URLRouting {
	public static void main(String[] args) {
		String requestURI = "https://localhost:9000/webproject/request.jsp";
		String contextPath = "https://localhost:9000/webproject";
		
		String command = requestURI.substring(contextPath.length()) ;
		System.out.println(command);
	}
}
​

 

SelectionSort

package algorithm;

public class QuickSort {
	
	private static void quickSort(int left, int right, int[] data) {
		//정렬 결과 출력
		for(int temp: data) {
			System.out.print(temp+"\t");
		}
		System.out.println();
		
		//가장 왼쪽의 데이터를 pivot으로 설정
		int pivot = left;
		//피봇의 취치를 .j에 대입
		int j = pivot;
		//피복솨 비교할 데이터의 위치의 초기값을 설정
		int i = left+1;
		if(left < right) {
			for(; i <= right; i= i+1) {
				if(data[i] < data[pivot]) {
					j= j+1;
					int temp = data[j];
					data[j] = data[i];
					data[i] = temp;
				}
			}
			int temp = data[left];
			data[left] = data[j];
			data[j] = temp;
			//1 
			pivot = j;
			quickSort(left, pivot -1, data);
			//2
			quickSort(pivot +1, right, data);
		}
	}
	
	
	public static void main(String[] args) {
		int[] list = {5,3,8,4,9,1,6,2,7};
		int n = list.length;
		//퀵 정렬 수행(left: 배열의 시작 = 0 ,right: 배열의 끝 = 8)
		quickSort(0, n-1, list);
		//정렬 결과 출력
		for(int temp: list) {
			System.out.print(temp+"\t");
		}
		System.out.println();
	}

}

 

URLRouting

package algorithm;

public class SelectionSort {
	public static void main(String[] args) {
		int [] ar = {20,30,10,50,40};
		for(int i = 0; i< ar.length ; i = i+1) {
			for(int j = i+1; j < ar.length; j= j+1) {
				if(ar[i] > ar[j]) {
					int temp = ar[i];
					ar[i] = ar[j];
					ar[j] = temp;
				}
			}
		}
		
		for(int item:ar) {
			System.out.print(item+"\t");
		}
	}
}

 

반응형

'Study > Java' 카테고리의 다른 글

java-20  (0) 2020.10.10
java-19  (0) 2020.10.10
java-18  (0) 2020.10.10
java-17  (0) 2020.10.10
java-16  (0) 2020.10.10

+ Recent posts