2010년 11월 8일 월요일
string serial
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.StringTokenizer;
/**
*
* @author Ko Hyang Gu
*/
class StringData implements Serializable{
String str = null;
public StringData(String str){
this.str = str;
}
public String getData(){
return this.str;
}
}
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
// TODO code application logic here
int len = args.length;
int index = 0;
StringBuffer sb = new StringBuffer();
while(len>0){
sb.append(args[index]);
sb.append(" ");
index++;
len--;
}
StringData sd = new StringData(sb.toString());
FileOutputStream fo = new FileOutputStream("a.data");
ObjectOutputStream oo = new ObjectOutputStream(fo);
oo.writeObject(sd);
oo.close();
FileInputStream fi = new FileInputStream("a.data");
ObjectInputStream oi = new ObjectInputStream(fi);
StringData sdi = (StringData)oi.readObject();
oi.close();
String temp = sdi.getData();
System.out.println("deserial string "+temp);
StringTokenizer st = new StringTokenizer(temp);
int num = st.countTokens();
System.out.println("deserial string num "+num);
String[] sa = new String[num];
while(st.hasMoreTokens()){
System.out.println("deserial string value "+st.nextToken());
}
}
2010년 11월 6일 토요일
Ajax
AJAX란? 'Asynchronous JavaScript + XML'의 줄임말 ('비동기 자바스크립트 XML) 즉, 자바스크립트와 XML 로 이루어진 기술이다.
교육중에 처음으로 자세히 소개 받게 되었는데, 현재, 차세대 웹 개발 기술로 각광 받고 있다
AJAX는 웹서버와 브라우저 사이에 AJAX엔진 하나가 더 위치하게 된다. 그 구조는 아래의 그림을 참조하시길...
이것이 어떠한 기술인지 가장 간단하게 설명하자면, 네이버 검색시 단어를 치면 밑으로 유사한 단어들이 바로 나열되게 된다.
또한, 구글의 맵(http://maps.google.com/)도 이 기술을 사용하였다. (AJAX는 구글에서 강력하게 밀고 있기도 하다) 구글지도의 Satellite 을 누르면, 위와같은 화면을 볼수 있는데, 더 확대가 가능하다. 꼭, 심시티의 한장면을 보는듯... 이용해 보면 알겠지만, 굉장히 빠르게 화면이 전환된다.
AJAX의 장점은 1. 빠르다 2. 호환성, 확장성이 높다 3. 별도의 프로그램( ActiveX또는 자바 애플릿)의 설치 없이 사용가능하다 4. 더욱 액티브한 화면 개발이 용이하다
이 외에도 많은 장점이 있겠지만, AJAX는 html은 물론이고, xml, css, 자바스크립트, 비동기 통신등 굉장히 많은 기술을 통합하여 사용한다. 때문에 이러한 기술 뿐아니라, 웹표준과 웹접근을 위한 구조등에 관한 기본적인 이해가 있어야만 제대로 사용할수 있다.
좀더 자세히 알고 싶다면 아래의 싸이트를 참고하여 개념정리를 하시길... http://www.dal.kr/chair/semanticweb/sw0701.html http://www.dal.kr/chair/semanticweb/sw0702.html http://www.dal.kr/chair/semanticweb/sw0703.html http://www.dal.kr/chair/semanticweb/sw0704.html 내용정리 ---> http://blog.naver.com/geena618/39839869 (내 블로그안에)
그리고 http://www.javapassion.com/ajaxcodecamp/ 으로 가면, 18주 코스로 배울수 있다.
모질라 제공, AJAX Getting_Started http://developer.mozilla.org/en/docs/AJAX:Getting_Started
언제나 느끼는 거지만, IT의 세계는 굉장히 빠른 속도로 발전해 가고 있는듯... 과연 언제까지 따라갈수 있을까? [출처] 아작스[AJAX] 간단 소개|작성자 포그니 |
2010년 11월 5일 금요일
2010년 11월 3일 수요일
2010년 11월 2일 화요일
2010년 11월 1일 월요일
quicksort
Quicksort
Quicksort is a fast sorting algorithm, which is used not only for educational purposes, but widely applied in practice. On the average, it has O(n log n) complexity, making quicksort suitable for sorting big data volumes. The idea of the algorithm is quite simple and once you realize it, you can write quicksort as fast as bubble sort.
Algorithm
The divide-and-conquer strategy is used in quicksort. Below the recursion step is described:- Choose a pivot value. We take the value of the middle element as pivot value, but it can be any value, which is in range of sorted values, even if it doesn't present in the array.
- Partition. Rearrange elements in such a way, that all elements which are lesser than the pivot go to the left part of the array and all elements greater than the pivot, go to the right part of the array. Values equal to the pivot can stay in any part of the array. Notice, that array may be divided in non-equal parts.
- Sort both parts. Apply quicksort algorithm recursively to the left and the right parts.
Partition algorithm in detail
There are two indices i and j and at the very beginning of the partition algorithm i points to the first element in the array and j points to the last one. Then algorithm moves i forward, until an element with value greater or equal to the pivot is found. Index j is moved backward, until an element with value lesser or equal to the pivot is found. If i ≤ j then they are swapped and i steps to the next position (i + 1), j steps to the previous one (j - 1). Algorithm stops, when i becomes greater than j.
After partition, all values before i-th element are less or equal than the pivot and all values after j-th element are greater or equal to the pivot.
Example. Sort {1, 12, 5, 26, 7, 14, 3, 7, 2} using quicksort.Notice, that we show here only the first recursion step, in order not to make example too long. But, in fact, {1, 2, 5, 7, 3} and {14, 7, 26, 12} are sorted then recursively.
Why does it work?
On the partition step algorithm divides the array into two parts and every element a from the left part is less or equal than every element b from the right part. Also a and b satisfy a ≤ pivot ≤ b inequality. After completion of the recursion calls both of the parts become sorted and, taking into account arguments stated above, the whole array is sorted.Complexity analysis
On the average quicksort has O(n log n) complexity, but strong proof of this fact is not trivial and not presented here. Still, you can find the proof in [1]. In worst case, quicksort runs O(n2) time, but on the most "practical" data it works just fine and outperforms other O(n log n) sorting algorithms.
Code snippets
Partition algorithm is important per se, therefore it may be carried out as a separate function. The code for C++ contains solid function for quicksort, but Java code contains two separate functions for partition and sort, accordingly.
http://www.algolist.net/Algorithms/Sorting/Quicksort