프로그래밍 언어/프로그래밍11 [JAVA] 채팅 서버, 클라이언트 예제 ================== 서버 ============================ public class Server {public static void main(String[] arg){ServerSocket server = null;BufferedReader in = null;try{// 서버 포트번호 셋팅server = new ServerSocket(12345);System.out.println("Server Ready");while(true){// 클라이언트가 보내는 연결요청을 기다린다.Socket s = server.accept();// 클라이언트가 보낸 데이터를 읽는 객체를 생성한다.in = new BufferedReader(new InputStreamReader(s.getInputS.. 프로그래밍 언어/프로그래밍 2016. 10. 2. [JAVA] 스트림 입출력 형식 종류별 스트림 1바이트 입출력 형식 1. 콘솔 출력 FileOutputStream fos = new FileOutputStream(FileDescriptor.out);BufferedOutputStream bos = new BufferedOutputStream(fos, 1024);DataOutputStream dos = new DataOutputStream(bos);dos.write() 입력 FieInputStream fis = new FileInputStream(FileDescriptor.in);BufferedInputStream bis = new BufferedInputStream(fis,1024);DataInputStream dis = new DataInputStream(bis);dis.read() .. 프로그래밍 언어/프로그래밍 2016. 9. 30. [유니티] 오브젝트 터치좌표로 이동하기 Update() 함수에 추가 if (isMoveState) { //Vector3 targetPos = transform.position + hitPosition; Vector3 dir = hitPosition - transform.position; Vector3 dirXY = new Vector3(dir.x, dir.y , 0); //Vector3 targetPos = transform.position + (hitPosition - transform.position); Vector3 targetPos = transform.position + dirXY; Vector3 framePos = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Tim.. 프로그래밍 언어/프로그래밍 2016. 6. 17. 유니티 점프 리지디바디로 점프 - 물리적 점프GetComponent().velocity = new Vector2(GetComponent().velocity.x, jump); 리지디바디 사용안하고 점프 - 계산식으로 만든 점프 private Vector3 moveDirection = Vector3.zero; Vector3 targetDirection = (new Vector3(CrossPlatformInputManager.GetAxis("Horizontal") * speed, 0f, CrossPlatformInputManager.GetAxis("Vertical") * speed)); if (targetDirection != Vector3.zero) { moveDirection = targetDirection; move.. 프로그래밍 언어/프로그래밍 2016. 6. 8. 해시 테이블 (hash table) // 해시 테이블이기는하나 완벽하지 않다.. // 리스트 10칸에 10칸씩 리스트 되어야 맞는 것 같으나 그냥 리스트 10칸에서 다시 해시가 적용된다.. #include #include #include #define TABLE_SIZE 10; typedef struct _node NODE; struct _node { int key; NODE *next; }; int hash_func(int key) { int h; h = key % TABLE_SIZE; return h; } int hsc_init(NODE a[],int *np,int N) { int i; for(i=0;inext = a[tri].next; /* a[tri]는 테이블의 첫라인만 가리킬뿐 값은 들어있지않다. */ t->key = key; /.. 프로그래밍 언어/프로그래밍 2009. 1. 18. 트리 #include #include #include #include typedef struct node NODE; struct node { int key; NODE *parent; NODE *left; NODE *right; }; NODE *root; NODE* node_search(int key, NODE *root) { NODE *s; s = root->left; while(key != s->key && s != NULL) { if(key key ) s = s->left; if(key > s->key ) s = s->right; } if(s == NULL) return NULL; else return s; } NODE * node_insert(int key) { NODE *p,*s; p = ro.. 프로그래밍 언어/프로그래밍 2009. 1. 18. 연결 리스트 (문장<이름>) #include #include #include #include typedef struct node NODE; struct node { char x[6]; NODE *prev; NODE *next; }; NODE *head = NULL; NODE *tail = NULL; NODE* Find_Node(char *x) { NODE *node; node = (NODE*)malloc(sizeof(NODE)); node = head->next; while(node != tail) { if(strcmp(node->x,x) next != tail) { node = node->next; continue; } else return node; if( strcmp(node->x,x) == 0 ) .. 프로그래밍 언어/프로그래밍 2009. 1. 18. 연결 리스트 (한 글자) #include #include #include typedef struct node NODE; typedef struct node { char x[3]; NODE *prev; NODE *next; }NODE; NODE *head = NULL; NODE *tail = NULL; NODE* Find_Node(char *x) { NODE *node; node = (NODE*)malloc(sizeof(NODE)); node = head->next; while(node != tail) { if( strcmp(node->x,x) x,x) == 0) return node; else if( strcmp(node->x,x) > 0 ) return n.. 프로그래밍 언어/프로그래밍 2009. 1. 18. 퀵정렬 #include void quick_sort(int a[],int n) { int v,t; int i,j; if(n>1) { v = a[n-1]; i = -1; j = n-1; while(1) { while(a[++i] v); if( i >=j ) break; t = a[i]; a[i] = a[j]; a[j] = t; } t = a[i]; a[i] = a[n-1]; a[n-1] = t; quick_sort(a,i); quick_sort(a+i+1,n-i-1); } } void main() { int q; int a[10] = {6,3,1,4,2,9,7,0,8,5}; quick_sort(a,10); for(q=0;q 프로그래밍 언어/프로그래밍 2009. 1. 18. 원형큐 #include #define MAX 10 int front,rear; char queue[MAX]; void init_queue() { front = rear = 0; } void clear_queue() { front = rear; } int put(char* ch) { if( (rear+1)%MAX == front ) return -1; queue[rear] = *ch; rear = ++rear % MAX; return 0; } int get(char* ch) { if( rear == front ) return -1; *ch = queue[front]; front = ++front % MAX; return 0; } void main() { char a,b,c; init_queue(); put("1".. 프로그래밍 언어/프로그래밍 2009. 1. 18. 스택 #include #include #define MAX 10 int top; char stack[MAX]; void init_stack() { top = -1; } int push(char* ch) { if(top >= MAX-1) return -1; stack[++top] = *ch; } int put(char* ch) { if( top < 0 ) { printf("\nfailed\n"); return -1; } *ch = stack[top--]; } void main() { char a,b,c,d; init_stack(); put(&b); put(&c); put(&d); printf("%c%c%c",a,b,c); } 프로그래밍 언어/프로그래밍 2009. 1. 17. 이전 1 다음