금요일, 3월 29
Shadow

#002 정렬 두가지 방법 순차정렬(앞뒤)

/*
* Main.java
*
* Created on 2006년 7월 25일 (화), 오전 11:12
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/

package array;

/**
*
* @author Administrator
*/
public class Main {

/** Creates a new instance of Main */
public Main() {
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
int[] ArrayData ={10,20,50,45,4,22,31,41};
int[] ArrayData1={10,20,50,45,4,22,31,41};
//postfix
for(int i=0;i<ArrayData.length;i++){
for(int j=i;j<ArrayData.length;j++){
if(ArrayData[j]<ArrayData[i]){
int temp=ArrayData[j];
ArrayData[j]=ArrayData[i];
ArrayData[i]=temp;
}

}

}

for(int k= 0; k<ArrayData.length;k++){
System.out.print(ArrayData[k]+ ” “);
}
System.out.println();

//infix
for(int i=(ArrayData1.length)-1;i>=0;i–){
for(int j=0;j<i;j++){
if(ArrayData1[i]<ArrayData1[j]){
int temp=ArrayData1[i];
ArrayData1[i]=ArrayData1[j];
ArrayData1[j]=temp;}
}
}

for(int k= 0; k<ArrayData1.length;k++){
System.out.print(ArrayData1[k]+ ” “);
}
System.out.println();
}

}

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.