Data Structure, Algorithm
-
[Algorithm] - 사각형 가로 세로 비율 구하기(Aspect Rectangle Ratio)Data Structure, Algorithm 2017. 2. 20. 08:27
가로 세로 비율 구하기 public class RectangleRatio { public int WidthRatio { get; set; } public int HeightRatio { get; set; } private RectangleRatio() : this(0, 0) { } private RectangleRatio(int widthRatio, int heightRatio) { WidthRatio = widthRatio; HeightRatio = heightRatio; } public static RectangleRatio ToRectangleRatio(int width, int height) { if (!(width >= 0 && height >= 0)) { throw new ArgumentExc..
-
[Algorithm] - 오름차순(Ascending), 내림차순(Descending) 정렬Data Structure, Algorithm 2016. 3. 8. 22:58
#include #pragma warning(disable:4715) typedef enum _SORT_COMPARE_TYPE { ASCENDING, DESCEDING } SORT_COMPARE_TYPE; typedef int(*pfnSortCompare)(int [], int, int); pfnSortCompare GetFuncSortCompareByType(SORT_COMPARE_TYPE compareType); int Ascending(int arr[], int x, int y); int Descending(int arr[], int x, int y); void Swap(int arr[], int x, int y); void Sort(int arr[], int nCount, pfnSortCompar..
-
[Algorithm] - 선형 탐색(Linear Search)Data Structure, Algorithm 2016. 3. 5. 12:50
#include using std::cout; using std::endl; int LinearSearch(int arr[], int len, int target) { for (int i = 0; i < len; i++) { if (target == arr[i]) { return i; } } return -1; } int main(void) { int arr[] = { 3, 5, 2, 4, 9 }; int index = LinearSearch(arr, sizeof(arr) ⁄ sizeof(arr[0]), 4); if (index == -1) { cout