목록Programming/C (23)
밍키의 마법세상
bubble sort는 6 5 4 3 2 1 5 6 4 3 2 1 5 4 6 3 2 1 5 4 3 6 2 1 5 4 3 2 1 6 위처럼 한번 시행에서 배열 안의 최대값은 배열의 맨 뒤에 위치하게 된다. 그러므로 다음 시행에서는 n-1번까지만 정렬을 해주면 된다. 항상 n^2만큼의 시간복잡도를 갖게 된다. - C 구현 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 #include void swap(int *n1, int *n2); void bubble_sort(int list[]); int main(){ int list[10]; for(int i = 0; i
KMP 알고리즘 사용 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416..
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455#include int i;int LinearSearch(int a[], int len, int num){ for(i = 0; i
12345678910111213141516171819202122232425262728293031323334353637383940#include #include #include #include #define swap(a,b,t){t = a; a = b; b = t;}int i, j, t, n = 5; void input(int a[]){ srand(time(NULL)); for (i = 0; i
123456789101112131415161718192021222324252627282930313233343536373839404142#include #include #include #include #define swap(a,b,t){t = a; a = b; b = t;}int i, j, t, n = 5; void input(int a[]){ srand(time(NULL)); for (i = 0; i
123456789101112131415161718192021222324252627#include #include int main(){ char a[100]; char seps[] = " "; char *token; printf("Input : "); gets(a); token = strtok(a, seps); while (token != '\0'){ printf("%s ", token); token = strtok(NULL, seps); if (token == '\0'){ break; } printf("%s\n", token); } return 0;}cs
1234567891011121314151617181920212223242526#include int main(){ char a[51], b[11]; printf("Input(a) : "); gets(a); printf("Input(b) : "); gets(b); int i = 0, j = 0, flag = 0; while (a[i] != '\0'){ if (b[j] == a[i]){ if (b[j + 1] == '\0'){ flag++; break; } else j++; } else j = 0; i++; } printf("%d %d", i, flag); return 0;}Colored by Color Scriptercs
음... 우선 메모리 구조에 대해 먼저 알아보자! CODE 함수, 제어문, 상수영역 DATA 전역 변수 BSS 전역 변수 HEAP 동적 할당 STACK 지역 변수 프로그램을 실행시키면 운영체제는 우리가 실행시킨 프로그램을 위해 메모리 공간을 할당해준다. 할당되는 메모리 공간은 크게 Stack, Heap, Data로 나뉜다! DATA, BSS--> 전역 변수와 static 변수가 할당되는 영역프로그램의 시작과 동시에 할당되고, 프로그램이 종료되어야 메모리에서 소멸됨BSS에는 초기화되지 않은 변수가,DATA에는 초기화된 변수가 들어간다! 123456789#include"stdio.h" int a = 10;int b = 20;int main(){ return 0;}cs a 와 b 는 프로그램이 종료될 때까지 ..