├── .gitignore
├── Ex0001_StandardLibraries
├── Ex0001_StandardLibraries.cpp
├── Ex0001_StandardLibraries.vcxproj
└── Ex0001_StandardLibraries.vcxproj.filters
├── Ex0002_WarmingUp
├── Ex0002_WarmingUp.cpp
├── Ex0002_WarmingUp.vcxproj
└── Ex0002_WarmingUp.vcxproj.filters
├── Ex0101_Addition
├── Ex0101_Addition.cpp
├── Ex0101_Addition.vcxproj
└── Ex0101_Addition.vcxproj.filters
├── Ex0102_Subtraction
├── Ex0102_Subtraction.cpp
├── Ex0102_Subtraction.vcxproj
└── Ex0102_Subtraction.vcxproj.filters
├── Ex0103_Multiplication
├── Ex0103_Multiplication.cpp
├── Ex0103_Multiplication.vcxproj
└── Ex0103_Multiplication.vcxproj.filters
├── Ex0104_Karatsuba
├── Ex0104_Karatsuba.cpp
├── Ex0104_Karatsuba.vcxproj
└── Ex0104_Karatsuba.vcxproj.filters
├── Ex0201_InsertionSort
├── Ex0201_InsertionSort.cpp
├── Ex0201_InsertionSort.vcxproj
└── Ex0201_InsertionSort.vcxproj.filters
├── Ex0202_InsertionSortPerformance
├── Ex0202_InsertionSortPerformance.cpp
├── Ex0202_InsertionSortPerformance.vcxproj
└── Ex0202_InsertionSortPerformance.vcxproj.filters
├── Ex0301_TopdownMergesort
├── Ex0301_TopdownMergesort.cpp
├── Ex0301_TopdownMergesort.vcxproj
└── Ex0301_TopdownMergesort.vcxproj.filters
├── Ex0302_BottomupMergesort
├── Ex0302_BottomupMergesort.cpp
├── Ex0302_BottomupMergesort.vcxproj
└── Ex0302_BottomupMergesort.vcxproj.filters
├── Ex0401_CountOccurrences
├── Ex0401_CountOccurrences.cpp
├── Ex0401_CountOccurrences.vcxproj
└── Ex0401_CountOccurrences.vcxproj.filters
├── Ex0402_PartialSelectionSort
├── Ex0402_PartialSelectionSort.cpp
├── Ex0402_PartialSelectionSort.vcxproj
└── Ex0402_PartialSelectionSort.vcxproj.filters
├── Ex0403_MinAndMax
├── Ex0403_MinAndMax.cpp
├── Ex0403_MinAndMax.vcxproj
└── Ex0403_MinAndMax.vcxproj.filters
├── Ex0404_PartitionByPivot
├── Ex0404_PartitionByPivot.cpp
├── Ex0404_PartitionByPivot.vcxproj
└── Ex0404_PartitionByPivot.vcxproj.filters
├── Ex0405_ExpectedLinearSelection
├── Ex0405_ExpectedLinearSelection.cpp
├── Ex0405_ExpectedLinearSelection.vcxproj
└── Ex0405_ExpectedLinearSelection.vcxproj.filters
├── Ex0406_WorstcaseLinearSelection
├── Ex0406_WorstcaseLinearSelection.cpp
├── Ex0406_WorstcaseLinearSelection.vcxproj
└── Ex0406_WorstcaseLinearSelection.vcxproj.filters
├── Ex0501_RandomizedQuicksort
├── Ex0501_RandomizedQuicksort.cpp
├── Ex0501_RandomizedQuicksort.vcxproj
└── Ex0501_RandomizedQuicksort.vcxproj.filters
├── Ex0502_Quick3way
├── Ex0502_Quick3way.cpp
├── Ex0502_Quick3way.vcxproj
└── Ex0502_Quick3way.vcxproj.filters
├── Ex0601_CountingSort
├── Ex0601_CountingSort.cpp
├── Ex0601_CountingSort.vcxproj
└── Ex0601_CountingSort.vcxproj.filters
├── Ex0602_RadixSort
├── Ex0602_RadixSort.cpp
├── Ex0602_RadixSort.vcxproj
└── Ex0602_RadixSort.vcxproj.filters
├── Ex0603_SortingWords
├── Ex0603_SortingWords.cpp
├── Ex0603_SortingWords.vcxproj
└── Ex0603_SortingWords.vcxproj.filters
├── Ex0604_BucketSort
├── Ex0604_BucketSort.cpp
├── Ex0604_BucketSort.vcxproj
└── Ex0604_BucketSort.vcxproj.filters
├── Ex0701_RedBlackTree
├── Ex0701_RedBlackTree.cpp
├── Ex0701_RedBlackTree.vcxproj
└── Ex0701_RedBlackTree.vcxproj.filters
├── Ex0801_SeparateChaining
├── Ex0801_SeparateChaining.cpp
├── Ex0801_SeparateChaining.vcxproj
└── Ex0801_SeparateChaining.vcxproj.filters
├── Ex0802_UnorderedMap
├── Ex0802_UnorderedMap.cpp
├── Ex0802_UnorderedMap.vcxproj
└── Ex0802_UnorderedMap.vcxproj.filters
├── Ex0803_RomanNumeral
├── Ex0803_RomanNumeral.cpp
├── Ex0803_RomanNumeral.vcxproj
└── Ex0803_RomanNumeral.vcxproj.filters
├── Ex0901_DepthFirstPaths
├── Ex0901_DepthFirstPaths.cpp
├── Ex0901_DepthFirstPaths.vcxproj
└── Ex0901_DepthFirstPaths.vcxproj.filters
├── Ex0902_QueueBasedTopologicalSorting
├── Ex0902_QueueBasedTopologicalSorting.cpp
├── Ex0902_QueueBasedTopologicalSorting.vcxproj
└── Ex0902_QueueBasedTopologicalSorting.vcxproj.filters
├── Ex0903_TopologicalSorting
├── Ex0903_TopologicalSorting.cpp
├── Ex0903_TopologicalSorting.vcxproj
└── Ex0903_TopologicalSorting.vcxproj.filters
├── Ex0904_DegreesOfSeparation
├── Ex0904_DegreesOfSeparation.cpp
├── Ex0904_DegreesOfSeparation.vcxproj
├── Ex0904_DegreesOfSeparation.vcxproj.filters
└── movies.txt
├── Ex0905_SymbolGraph
├── Ex0905_SymbolGraph.cpp
├── Ex0905_SymbolGraph.vcxproj
└── Ex0905_SymbolGraph.vcxproj.filters
├── Ex0906_DirectedCycleDetection
├── Ex0906_DirectedCycleDetection.cpp
├── Ex0906_DirectedCycleDetection.vcxproj
└── Ex0906_DirectedCycleDetection.vcxproj.filters
├── Ex0908_TracingDFS
├── Ex0908_TracingDFS.cpp
├── Ex0908_TracingDFS.vcxproj
└── Ex0908_TracingDFS.vcxproj.filters
├── Ex1001_ConnectedComponents
├── Ex1001_ConnectedComponents.cpp
├── Ex1001_ConnectedComponents.vcxproj
└── Ex1001_ConnectedComponents.vcxproj.filters
├── Ex1002_StrongComponents(BruteForce)
├── Ex1002_StrongComponents(BruteForce).cpp
├── Ex1002_StrongComponents(BruteForce).vcxproj
└── Ex1002_StrongComponents(BruteForce).vcxproj.filters
├── Ex1003_KosarajuStrongComponents
├── Ex1003_KosarajuStrongComponents.cpp
├── Ex1003_KosarajuStrongComponents.vcxproj
└── Ex1003_KosarajuStrongComponents.vcxproj.filters
├── Ex1101_PriorityQueue
├── Ex1101_PriorityQueue.cpp
├── Ex1101_PriorityQueue.vcxproj
└── Ex1101_PriorityQueue.vcxproj.filters
├── Ex1102_IndexMinPQ
├── Ex1102_IndexMinPQ.cpp
├── Ex1102_IndexMinPQ.vcxproj
├── Ex1102_IndexMinPQ.vcxproj.filters
└── IndexMinPQ.h
├── Ex1103_Dijkstra(IndexMinPQ)
├── Ex1103_Dijkstra(IndexMinPQ).cpp
├── Ex1103_Dijkstra(IndexMinPQ).vcxproj
└── Ex1103_Dijkstra(IndexMinPQ).vcxproj.filters
├── Ex1104_Dijkstra(LinearSearch)
├── Ex1104_Dijkstra(LinearSearch).cpp
├── Ex1104_Dijkstra(LinearSearch).vcxproj
└── Ex1104_Dijkstra(LinearSearch).vcxproj.filters
├── Ex1105_Dijkstra
├── Ex1105_Dijkstra.cpp
├── Ex1105_Dijkstra.vcxproj
└── Ex1105_Dijkstra.vcxproj.filters
├── Ex1201_Fibonacci
├── Ex1201_Fibonacci.cpp
├── Ex1201_Fibonacci.vcxproj
└── Ex1201_Fibonacci.vcxproj.filters
├── Ex1202_RodCutting
├── Ex1202_RodCutting.cpp
├── Ex1202_RodCutting.vcxproj
└── Ex1202_RodCutting.vcxproj.filters
├── Ex1203_BellmanFord
├── Ex1203_BellmanFord.cpp
├── Ex1203_BellmanFord.vcxproj
└── Ex1203_BellmanFord.vcxproj.filters
├── Ex1204_Arbitrage
├── Ex1204_Arbitrage.cpp
├── Ex1204_Arbitrage.vcxproj
└── Ex1204_Arbitrage.vcxproj.filters
├── Ex1205_FloydWarshall
├── Ex1205_FloydWarshall.cpp
├── Ex1205_FloydWarshall.vcxproj
└── Ex1205_FloydWarshall.vcxproj.filters
├── Ex1301_LongestCommonSequence
├── Ex1301_LongestCommonSequence.cpp
├── Ex1301_LongestCommonSequence.vcxproj
└── Ex1301_LongestCommonSequence.vcxproj.filters
├── Ex1302_ZeroOneKnapsack
├── Ex1302_ZeroOneKnapsack.cpp
├── Ex1302_ZeroOneKnapsack.vcxproj
└── Ex1302_ZeroOneKnapsack.vcxproj.filters
├── Ex1303_UnboundedKnapsack
├── Ex1303_UnboundedKnapsack.cpp
├── Ex1303_UnboundedKnapsack.vcxproj
└── Ex1303_UnboundedKnapsack.vcxproj.filters
├── Ex1304_LargestIndependentSet
├── Ex1304_LargestIndependentSet.cpp
├── Ex1304_LargestIndependentSet.vcxproj
└── Ex1304_LargestIndependentSet.vcxproj.filters
├── Ex1401_FractionalKnapsack
├── Ex1401_FractionalKnapsack.cpp
├── Ex1401_FractionalKnapsack.vcxproj
└── Ex1401_FractionalKnapsack.vcxproj.filters
├── Ex1402_ActivitySelection
├── Ex1402_ActivitySelection.cpp
├── Ex1402_ActivitySelection.vcxproj
└── Ex1402_ActivitySelection.vcxproj.filters
├── Ex1403_HuffmanCoding
├── Ex1403_HuffmanCoding.cpp
├── Ex1403_HuffmanCoding.vcxproj
└── Ex1403_HuffmanCoding.vcxproj.filters
├── Ex1501_PrimMST
├── Ex1501_PrimMST.cpp
├── Ex1501_PrimMST.vcxproj
└── Ex1501_PrimMST.vcxproj.filters
├── Ex1502_UnionFind
├── Ex1502_UnionFind.cpp
├── Ex1502_UnionFind.vcxproj
├── Ex1502_UnionFind.vcxproj.filters
└── UnionFind.h
├── Ex1503_KruskalMST
├── Ex1503_KruskalMST.cpp
├── Ex1503_KruskalMST.vcxproj
└── Ex1503_KruskalMST.vcxproj.filters
├── Ex1601_FordFulkerson
├── Ex1601_FordFulkerson.cpp
├── Ex1601_FordFulkerson.vcxproj
└── Ex1601_FordFulkerson.vcxproj.filters
├── Ex1701_BipartiteGraph
├── Ex1701_BipartiteGraph.cpp
├── Ex1701_BipartiteGraph.vcxproj
└── Ex1701_BipartiteGraph.vcxproj.filters
├── Ex1702_GaleShapley
├── Ex1702_GaleShapley.cpp
├── Ex1702_GaleShapley.vcxproj
└── Ex1702_GaleShapley.vcxproj.filters
├── Ex1801_LongestPath
├── Ex1801_LongestPath.cpp
├── Ex1801_LongestPath.vcxproj
└── Ex1801_LongestPath.vcxproj.filters
├── Ex1802_TravellingSalesmanProblem
├── Ex1802_TravellingSalesmanProblem.cpp
├── Ex1802_TravellingSalesmanProblem.vcxproj
└── Ex1802_TravellingSalesmanProblem.vcxproj.filters
├── HongLabAlgorithmsPart1.sln
├── README.md
├── VSCode
├── Ex0001_StandardLibraries
│ └── Ex0001_StandardLibraries.cpp
├── Ex0002_WarmingUp
│ └── Ex0002_WarmingUp.cpp
├── Ex0101_Addition
│ └── Ex0101_Addition.cpp
├── Ex0102_Subtraction
│ └── Ex0102_Subtraction.cpp
├── Ex0103_Multiplication
│ └── Ex0103_Multiplication.cpp
├── Ex0104_Karatsuba
│ └── Ex0104_Karatsuba.cpp
├── Ex0201_InsertionSort
│ └── Ex0201_InsertionSort.cpp
├── Ex0202_InsertionSortPerformance
│ └── Ex0202_InsertionSortPerformance.cpp
├── Ex0301_TopdownMergesort
│ └── Ex0301_TopdownMergesort.cpp
├── Ex0302_BottomupMergesort
│ └── Ex0302_BottomupMergesort.cpp
├── Ex0401_CountOccurrences
│ └── Ex0401_CountOccurrences.cpp
├── Ex0402_PartialSelectionSort
│ └── Ex0402_PartialSelectionSort.cpp
├── Ex0403_MinAndMax
│ └── Ex0403_MinAndMax.cpp
├── Ex0404_PartitionByPivot
│ └── Ex0404_PartitionByPivot.cpp
├── Ex0405_ExpectedLinearSelection
│ └── Ex0405_ExpectedLinearSelection.cpp
├── Ex0406_WorstcaseLinearSelection
│ └── Ex0406_WorstcaseLinearSelection.cpp
├── Ex0501_RandomizedQuicksort
│ └── Ex0501_RandomizedQuicksort.cpp
├── Ex0502_Quick3way
│ └── Ex0502_Quick3way.cpp
├── Ex0601_CountingSort
│ └── Ex0601_CountingSort.cpp
├── Ex0602_RadixSort
│ └── Ex0602_RadixSort.cpp
├── Ex0603_SortingWords
│ └── Ex0603_SortingWords.cpp
├── Ex0604_BucketSort
│ └── Ex0604_BucketSort.cpp
├── Ex0701_RedBlackTree
│ └── Ex0701_RedBlackTree.cpp
├── Ex0801_SeparateChaining
│ └── Ex0801_SeparateChaining.cpp
├── Ex0802_UnorderedMap
│ └── Ex0802_UnorderedMap.cpp
├── Ex0803_RomanNumeral
│ └── Ex0803_RomanNumeral.cpp
├── Ex0901_DepthFirstPaths
│ └── Ex0901_DepthFirstPaths.cpp
├── Ex0902_QueueBasedTopologicalSorting
│ └── Ex0902_QueueBasedTopologicalSorting.cpp
├── Ex0903_TopologicalSorting
│ └── Ex0903_TopologicalSorting.cpp
├── Ex0904_DegreesOfSeparation
│ └── Ex0904_DegreesOfSeparation.cpp
├── Ex0905_SymbolGraph
│ └── Ex0905_SymbolGraph.cpp
├── Ex0906_DirectedCycleDetection
│ └── Ex0906_DirectedCycleDetection.cpp
├── Ex0908_TracingDFS
│ └── Ex0908_TracingDFS.cpp
├── Ex1001_ConnectedComponents
│ └── Ex1001_ConnectedComponents.cpp
├── Ex1002_StrongComponents(BruteForce)
│ └── Ex1002_StrongComponents(BruteForce).cpp
├── Ex1003_KosarajuStrongComponents
│ └── Ex1003_KosarajuStrongComponents.cpp
├── Ex1101_PriorityQueue
│ └── Ex1101_PriorityQueue.cpp
├── Ex1102_IndexMinPQ
│ ├── Ex1102_IndexMinPQ.cpp
│ └── IndexMinPQ.h
├── Ex1103_Dijkstra(IndexMinPQ)
│ └── Ex1103_Dijkstra(IndexMinPQ).cpp
├── Ex1104_Dijkstra(LinearSearch)
│ └── Ex1104_Dijkstra(LinearSearch).cpp
├── Ex1105_Dijkstra
│ └── Ex1105_Dijkstra.cpp
├── Ex1201_Fibonacci
│ └── Ex1201_Fibonacci.cpp
├── Ex1202_RodCutting
│ └── Ex1202_RodCutting.cpp
├── Ex1203_BellmanFord
│ └── Ex1203_BellmanFord.cpp
├── Ex1204_Arbitrage
│ └── Ex1204_Arbitrage.cpp
├── Ex1205_FloydWarshall
│ └── Ex1205_FloydWarshall.cpp
├── Ex1301_LongestCommonSequence
│ └── Ex1301_LongestCommonSequence.cpp
├── Ex1302_ZeroOneKnapsack
│ └── Ex1302_ZeroOneKnapsack.cpp
├── Ex1303_UnboundedKnapsack
│ └── Ex1303_UnboundedKnapsack.cpp
├── Ex1304_LargestIndependentSet
│ └── Ex1304_LargestIndependentSet.cpp
├── Ex1401_FractionalKnapsack
│ └── Ex1401_FractionalKnapsack.cpp
├── Ex1402_ActivitySelection
│ └── Ex1402_ActivitySelection.cpp
├── Ex1403_HuffmanCoding
│ └── Ex1403_HuffmanCoding.cpp
├── Ex1501_PrimMST
│ └── Ex1501_PrimMST.cpp
├── Ex1502_UnionFind
│ ├── Ex1502_UnionFind.cpp
│ └── UnionFind.h
├── Ex1503_KruskalMST
│ └── Ex1503_KruskalMST.cpp
├── Ex1601_FordFulkerson
│ └── Ex1601_FordFulkerson.cpp
├── Ex1701_BipartiteGraph
│ └── Ex1701_BipartiteGraph.cpp
├── Ex1702_GaleShapley
│ └── Ex1702_GaleShapley.cpp
├── Ex1801_LongestPath
│ └── Ex1801_LongestPath.cpp
└── Ex1802_TravellingSalesmanProblem
│ └── Ex1802_TravellingSalesmanProblem.cpp
└── copy_files.py
/Ex0001_StandardLibraries/Ex0001_StandardLibraries.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0002_WarmingUp/Ex0002_WarmingUp.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | using namespace std;
4 |
5 | int main()
6 | {
7 | // 문제 1. 10진수 -> 2진수
8 | {
9 | int decimal = 105;
10 | string binary;
11 |
12 | //TODO:
13 |
14 | cout << binary << endl; // 1101001
15 | }
16 |
17 | // 문제 2. 문자열 뒤집기
18 | {
19 | string input = "Hello, World!";
20 |
21 | // TODO:
22 |
23 | cout << input << endl; // !dlroW ,olleH
24 | }
25 |
26 | // 문제 3. 모든 자리 다 더하기
27 | {
28 | string n = "789789";
29 |
30 | // TODO:
31 |
32 | cout << n << endl;
33 | }
34 |
35 | return 0;
36 | }
37 |
--------------------------------------------------------------------------------
/Ex0002_WarmingUp/Ex0002_WarmingUp.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0101_Addition/Ex0101_Addition.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | using namespace std;
6 |
7 | string Add(string str1, string str2)
8 | {
9 | // TODO:
10 |
11 | return string("0");
12 | }
13 |
14 | int main()
15 | {
16 | vector> tests = {
17 | {"12", "34", to_string(12 + 34)}
18 | , {"123", "45", to_string(123 + 45)}
19 | , {"54544", "44545", to_string(54544 + 44545)}
20 | , {"5555", "55", to_string(5555 + 55)}
21 | , {"5555", "5555", to_string(5555 + 5555)}
22 | , {"9823471235421415454545454545454544", "1714546546546545454544548544544545", "11538017781967960909090003089999089"}
23 | };
24 |
25 | for (const auto& t : tests)
26 | {
27 | const string str1 = t[0]; // "12"
28 | const string str2 = t[1]; // "34"
29 | const string expected = t[2]; // "46"
30 |
31 | cout << str1 << " + " << str2 << " = " << expected << endl;
32 |
33 | const string result = Add(str1, str2);
34 |
35 | cout << result << " " << expected << " ";
36 |
37 | if (result == expected)
38 | cout << "OK" << endl;
39 | else {
40 | cout << "Not OK" << endl;
41 | exit(-1);
42 | }
43 | cout << endl << endl;
44 | }
45 |
46 | cout << "Congratulations. All OK!" << endl;
47 |
48 | return 0;
49 | }
50 |
--------------------------------------------------------------------------------
/Ex0101_Addition/Ex0101_Addition.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0102_Subtraction/Ex0102_Subtraction.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | using namespace std;
6 |
7 | // 항상 큰 수에서 작은 수를 빼는 경우(결과가 음수가 되지 않는 경우)를 가정
8 | string Subtract(string str1, string str2)
9 | {
10 | // 둘이 같을 경우 바로 "0" 반환
11 | if (str1 == str2)
12 | return "0"; // '0'은 char, "0"은 string
13 |
14 | int N = max(str1.size(), str2.size());
15 | str1 = string(N - str1.size(), '0') + str1; // 문자열끼리의 더하기도 가능
16 | str2 = string(N - str2.size(), '0') + str2;
17 |
18 | string result(N, '0');
19 |
20 | // TODO: 더하기와 거의 비슷합니다.
21 |
22 | // 불필요한 '0' 제거 (예: "078" -> "78")
23 | // TODO:
24 |
25 | return result;
26 | }
27 |
28 | int main()
29 | {
30 | // 항상 큰 수에서 작은 수를 빼는 경우(결과가 음수가 되지 않는 경우)를 가정
31 | vector> tests = {
32 | {"34", "12", std::to_string(34 - 12)}
33 | , {"123", "45", std::to_string(123 - 45)}
34 | , {"54544", "44545", std::to_string(54544 - 44545)}
35 | , {"5555", "55", std::to_string(5555 - 55)}
36 | , {"5555", "5555", std::to_string(5555 - 5555)}
37 | , {"9823471235421415454545454545454544", "1714546546546545454544548544544545", "8108924688874870000000906000909999"}
38 | };
39 |
40 | for (const auto& t : tests)
41 | {
42 | const string str1 = t[0];
43 | const string str2 = t[1];
44 | const string expected = t[2];
45 |
46 | cout << str1 << " - " << str2 << " = " << expected << endl;
47 |
48 | const string result = Subtract(str1, str2);
49 |
50 | cout << result << " " << expected << " ";
51 |
52 | if (result == expected)
53 | cout << "OK";
54 | else {
55 | cout << "Not OK";
56 | exit(-1);
57 | }
58 | cout << endl << endl;
59 | }
60 |
61 | cout << "Congratulations. All OK!" << endl;
62 |
63 | return 0;
64 | }
65 |
--------------------------------------------------------------------------------
/Ex0102_Subtraction/Ex0102_Subtraction.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0103_Multiplication/Ex0103_Multiplication.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | using namespace std;
6 |
7 | string Multiply(string str1, string str2)
8 | {
9 | // TODO:
10 |
11 | return "0";
12 | }
13 |
14 | int main()
15 | {
16 | vector> tests = {
17 | {"12", "34", std::to_string(12 * 34)},
18 | {"123", "45", std::to_string(123 * 45)},
19 | {"5555", "55", std::to_string(5555 * 55)},
20 | {"5555", "5555", std::to_string(5555 * 5555)},
21 | {"98234712354214154", "171454654654655", "16842798681791158832220782986870"}
22 | // , {"9823471235421415454545454545454544", "1714546546546545454544548544544545", "16842798681791114273590624445460185389471221520083884298838480662480"}
23 | };
24 |
25 | for (const auto& t : tests)
26 | {
27 | const string str1 = t[0];
28 | const string str2 = t[1];
29 | const string expected = t[2];
30 |
31 | cout << str1 << " * " << str2 << " = " << expected << endl;
32 |
33 | const string result = Multiply(str1, str2);
34 |
35 | cout << result << " " << expected << " ";
36 |
37 | if (result == expected)
38 | cout << "OK";
39 | else {
40 | cout << "Not OK";
41 | exit(-1);
42 | }
43 | cout << endl << endl;
44 | }
45 |
46 | cout << "Congratulations. All OK!" << endl;
47 |
48 | return 0;
49 | }
50 |
--------------------------------------------------------------------------------
/Ex0103_Multiplication/Ex0103_Multiplication.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0104_Karatsuba/Ex0104_Karatsuba.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0201_InsertionSort/Ex0201_InsertionSort.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | using namespace std;
4 |
5 | bool CheckSorted(vector& arr)
6 | {
7 | for (int i = 0; i < arr.size() - 1; i++)
8 | {
9 | if (arr[i] > arr[i + 1])
10 | return false;
11 | }
12 |
13 | return true;
14 | }
15 |
16 | void Print(vector& arr)
17 | {
18 | for (auto v : arr)
19 | cout << v << " ";
20 | cout << endl;
21 | }
22 |
23 | int main()
24 | {
25 | // vector a = { 6, 5, 4, 3, 2, 1 };
26 | vector a = { 6, 4, 3, 8, 5 };
27 |
28 | int N = a.size();
29 | for (int i = 1; i < N; i++)
30 | {
31 | // TODO: 딱 2줄만 사용
32 |
33 | Print(a);
34 | }
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/Ex0201_InsertionSort/Ex0201_InsertionSort.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0202_InsertionSortPerformance/Ex0202_InsertionSortPerformance.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include // std::iota
8 |
9 | using namespace std;
10 | using namespace std::chrono;
11 |
12 | void Print(vector& arr)
13 | {
14 | for (int i = 0; i < arr.size(); i++)
15 | cout << arr[i] << " ";
16 | cout << endl;
17 | }
18 |
19 | bool CheckSorted(vector& a)
20 | {
21 | for (int i = 0; i < a.size() - 1; i++)
22 | {
23 | if (a[i] > a[i + 1])
24 | return false;
25 | }
26 |
27 | return true;
28 | }
29 |
30 | void InsertionSort1(vector& a)
31 | {
32 | int N = a.size();
33 | for (int i = 1; i < N; i++)
34 | for (int j = i; j > 0 && a[j - 1] > a[j]; j--)
35 | swap(a[j - 1], a[j]);
36 | }
37 |
38 | void InsertionSort2(vector& a)
39 | {
40 | int N = a.size();
41 | int i;
42 | for (i = 1; i < N; i++)
43 | {
44 | int key = a[i];
45 | int j = i;
46 | for (; j > 0 && a[j - 1] > key; j--)
47 | a[j] = a[j - 1];
48 | a[j] = key;
49 | }
50 | }
51 |
52 | struct Sample {
53 | int n;
54 | double duration;
55 | };
56 |
57 | int main()
58 | {
59 | random_device rd;
60 | mt19937 gen(rd());
61 |
62 | vector samples;
63 | samples.reserve(5000);
64 |
65 | for (int n = 1; n <= 5000; n += 1)
66 | {
67 | vector my_vector(n);
68 |
69 | for (int r = 0; r < n; r += max(1, n / 100))
70 | {
71 | // 0 이상 n-1 이하의 정수가 균일한 확률로 생성되는 난수 (uniform distribution)
72 | //uniform_int_distribution value_distribution(0, n - 1);
73 | //generate(my_vector.begin(), my_vector.end(), [&]() { return value_distribution(gen); });
74 |
75 | std::iota(my_vector.begin(), my_vector.end(), 0); // iota는 0, 1, 2, ... , n-1 까지 순서대로 채워주는 함수
76 | std::reverse(my_vector.begin(), my_vector.end()); // 최악의 경우를 만들기 위해 순서를 뒤집어주기
77 | std::random_shuffle(my_vector.begin(), my_vector.begin() + r); // 일부만 순서를 바꿔줌 (shuffle은 딜러가 카드 섞는 것 생각하면 됩니다.)
78 |
79 | // Print(my_vector);
80 |
81 | // Random case
82 | auto start = high_resolution_clock::now();
83 |
84 | InsertionSort2(my_vector);
85 |
86 | auto stop = high_resolution_clock::now();
87 | auto dur = double(duration_cast(stop - start).count()) / 1000000000.0;
88 |
89 | if (!CheckSorted(my_vector))
90 | {
91 | cout << "Failed." << endl;
92 | exit(-1);
93 | }
94 |
95 | samples.push_back({ n, dur });
96 |
97 | if (n % 1000 == 0 && r == 0)
98 | {
99 | cout << n << " : " << dur << endl;
100 | }
101 | }
102 | }
103 |
104 | ofstream ofile("result_insertion2_worstshuffle.txt");
105 | for (auto& s : samples)
106 | ofile << s.n << ", " << s.duration << endl;
107 |
108 | ofile.close();
109 |
110 | cout << "\a" << endl;
111 | }
112 |
--------------------------------------------------------------------------------
/Ex0202_InsertionSortPerformance/Ex0202_InsertionSortPerformance.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0301_TopdownMergesort/Ex0301_TopdownMergesort.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include // setfill(), setw()
4 | #include // iota
5 |
6 | using namespace std;
7 |
8 | void Print(vector& arr, int lo, int hi)
9 | {
10 | // setfill(), setw()는 줄맞춤에 사용
11 |
12 | for (int i = 0; i < lo; i++)
13 | cout << " ";
14 | for (int i = lo; i <= hi; i++)
15 | cout << setfill(' ') << setw(3) << arr[i];
16 | cout << endl;
17 | }
18 |
19 | bool CheckSorted(vector& a)
20 | {
21 | for (int i = 0; i < a.size() - 1; i++)
22 | {
23 | if (a[i] > a[i + 1])
24 | return false;
25 | }
26 |
27 | return true;
28 | }
29 |
30 | // Sedgewick p. 273
31 | class TopDownMerge
32 | {
33 | public:
34 | void Sort(vector& a)
35 | {
36 | count = 0; // 분석용
37 | aux.resize(a.size());
38 |
39 | SortHelper(a, 0, a.size() - 1);
40 | }
41 |
42 | private:
43 | void Merge(vector& a, int lo, int mid, int hi)
44 | {
45 | cout << "Before: ";
46 | Print(a, lo, hi);
47 |
48 | int i = lo, j = mid + 1;
49 |
50 | for (int k = lo; k <= hi; k++)
51 | aux[k] = a[k];
52 |
53 | for (int k = lo; k <= hi; k++)
54 | {
55 | //if (i > mid) TODO;
56 | //else if (j > hi) TODO;
57 | //else if (aux[j] < aux[i]) TODO;
58 | //else a[k] = TODO;
59 | }
60 |
61 | cout << "After : ";
62 | Print(a, lo, hi);
63 |
64 | //count += hi - lo + 1;
65 | //cout << "Count : " << hi - lo + 1 << ", " << count << endl; // 누적 카운트 (디버깅용)
66 | }
67 |
68 | void SortHelper(vector& a, int lo, int hi)
69 | {
70 | if (hi <= lo) return;
71 |
72 | int mid = lo + (hi - lo) / 2;
73 |
74 | //TODO:
75 | //TODO:
76 |
77 | Merge(a, lo, mid, hi);
78 | }
79 |
80 | vector aux; // 추가 메모리 필요
81 | int count = 0; // 연산 횟수 세보기용
82 | };
83 |
84 | int main()
85 | {
86 | vector my_vector(16);
87 | std::iota(my_vector.begin(), my_vector.end(), 0);
88 | std::reverse(my_vector.begin(), my_vector.end());
89 |
90 | cout << " ";
91 | Print(my_vector, 0, my_vector.size() - 1);
92 |
93 | TopDownMerge merge;
94 | merge.Sort(my_vector);
95 |
96 | cout << " ";
97 | Print(my_vector, 0, my_vector.size() - 1);
98 | }
99 |
--------------------------------------------------------------------------------
/Ex0301_TopdownMergesort/Ex0301_TopdownMergesort.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0302_BottomupMergesort/Ex0302_BottomupMergesort.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include // std::iota
5 |
6 | using namespace std;
7 |
8 | void Print(vector& arr, int lo, int hi)
9 | {
10 | // setfill(), setw()는 줄맞춤에 사용
11 |
12 | for (int i = 0; i < lo; i++)
13 | cout << " ";
14 | for (int i = lo; i <= hi; i++)
15 | cout << setfill(' ') << setw(3) << arr[i];
16 | cout << endl;
17 | }
18 |
19 | bool CheckSorted(vector& a)
20 | {
21 | for (int i = 0; i < a.size() - 1; i++)
22 | {
23 | if (a[i] > a[i + 1])
24 | return false;
25 | }
26 |
27 | return true;
28 | }
29 |
30 | // Sedgewick p. 278
31 | class BottomupMerge
32 | {
33 | public:
34 | void Sort(vector& a)
35 | {
36 | aux.resize(a.size());
37 |
38 | int N = a.size();
39 | // TODO: 재귀호출 사용하지 않습니다.
40 | }
41 |
42 | private:
43 | void Merge(vector& a, int lo, int mid, int hi)
44 | {
45 | // TODO: Top-down과 동일
46 | }
47 |
48 | vector aux; // 추가 메모리
49 | };
50 |
51 | int main()
52 | {
53 | vector my_vector(16);
54 | std::iota(my_vector.begin(), my_vector.end(), 0);
55 | std::reverse(my_vector.begin(), my_vector.end());
56 |
57 | cout << " ";
58 | Print(my_vector, 0, my_vector.size() - 1);
59 |
60 | BottomupMerge merge;
61 | merge.Sort(my_vector);
62 |
63 | cout << " ";
64 | Print(my_vector, 0, my_vector.size() - 1);
65 | }
66 |
--------------------------------------------------------------------------------
/Ex0302_BottomupMergesort/Ex0302_BottomupMergesort.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0401_CountOccurrences/Ex0401_CountOccurrences.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | using namespace std;
8 |
9 | void Print(vector& arr)
10 | {
11 | for (int i = 0; i < arr.size(); i++)
12 | cout << arr[i] << " ";
13 | cout << endl;
14 | }
15 |
16 | int Count1(const vector& arr, int x)
17 | {
18 | //TODO: O(n)
19 | return 0;
20 | }
21 |
22 | int Count2(const vector& arr, int x)
23 | {
24 | //TODO: O(log(n) + count)
25 | return 0;
26 | }
27 |
28 | int Count3(const vector& arr, int x)
29 | {
30 | //TODO: O(log(n))
31 | return 0;
32 | }
33 |
34 | int main()
35 | {
36 | random_device rd;
37 | mt19937 gen(rd());
38 |
39 | const int n = 20;
40 | vector my_vector(n);
41 |
42 | int x = 6; // target to find
43 |
44 | for (int r = 0; r < 100; r++)
45 | {
46 | uniform_int_distribution value_distribution(1, 10);
47 | generate(my_vector.begin(), my_vector.end(), [&]() { return value_distribution(gen); });
48 | sort(my_vector.begin(), my_vector.end());
49 |
50 | Print(my_vector);
51 |
52 | const int expected_count = std::count(my_vector.begin(), my_vector.end(), x);
53 |
54 | cout << "Expected count = " << expected_count << endl;
55 |
56 | // 1. O(n) brute force
57 | if (Count1(my_vector, x) != expected_count)
58 | {
59 | cout << "Wrong count1: " << Count1(my_vector, x) << endl;
60 | exit(-1);
61 | }
62 |
63 | // 2. O(log(n) + count)
64 | if (Count2(my_vector, x) != expected_count)
65 | {
66 | cout << "Wrong count2: " << Count2(my_vector, x) << endl;
67 | exit(-1);
68 | }
69 |
70 | // 3. O(log(n))
71 | if (Count3(my_vector, x) != expected_count)
72 | {
73 | cout << "Wrong count3: " << Count3(my_vector, x) << endl;
74 | exit(-1);
75 | }
76 | }
77 |
78 | cout << "Good!" << endl;
79 |
80 | return 0;
81 | }
82 |
--------------------------------------------------------------------------------
/Ex0401_CountOccurrences/Ex0401_CountOccurrences.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0402_PartialSelectionSort/Ex0402_PartialSelectionSort.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | using namespace std;
8 |
9 | void Print(vector& arr)
10 | {
11 | for (int i = 0; i < arr.size(); i++)
12 | cout << arr[i] << " ";
13 | cout << endl;
14 | }
15 |
16 | // 가장 작은 값이 arr[lo]에 오도록
17 | void SelectionSortPass(vector& arr, int lo, int hi)
18 | {
19 | // TODO:
20 | }
21 |
22 | void PartialSelectionSort(vector& arr, int k)
23 | {
24 | Print(arr);
25 |
26 | for (int i = 0; i < k; i++)
27 | {
28 | // SelectionSortPass( TODO: );
29 |
30 | Print(arr);
31 | }
32 | }
33 |
34 | int main()
35 | {
36 | vector my_vector = { 7, 10, 4, 3, 20, 15 };
37 |
38 | int k = 3;
39 |
40 | PartialSelectionSort(my_vector, k);
41 |
42 | cout << my_vector[k - 1] << endl;
43 | }
44 |
--------------------------------------------------------------------------------
/Ex0402_PartialSelectionSort/Ex0402_PartialSelectionSort.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0403_MinAndMax/Ex0403_MinAndMax.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | using namespace std;
4 |
5 | int main()
6 | {
7 | vector arr = { 8, 2, 3, 5, 9, 1, 9, 4, 3, 7, 6, 7 };
8 |
9 | // TODO:
10 |
11 | cout << "Min value = " << arr[0] << ", Max value = " << arr[1] << endl; // Min value = 1, Max value = 9
12 | }
13 |
--------------------------------------------------------------------------------
/Ex0403_MinAndMax/Ex0403_MinAndMax.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0404_PartitionByPivot/Ex0404_PartitionByPivot.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | using namespace std;
4 |
5 | void Print(vector& arr)
6 | {
7 | for (int i = 0; i < arr.size(); i++)
8 | cout << arr[i] << " ";
9 | cout << endl;
10 | }
11 |
12 | int main()
13 | {
14 | vector arr = { 5, 2, 7, 3, 8, 5, 6, 4 };
15 | //vector arr = { 2, 8, 7, 1, 3, 5, 6, 4 };
16 | //vector arr = { 9, 8, 7, 6, 4, 3, 2, 1, 5 };
17 | //vector arr = { 5, 2, 7, 3, 4, 4, 6, 4 };
18 |
19 | int lo = 0; // 첫 인덱스
20 | int hi = arr.size() - 1; // 마지막 인덱스
21 | int x = arr[hi]; // 분할 기준으로 사용하는 pivot 4
22 |
23 | int i = lo - 1; // pivot보다 것들중 가장 큰 인덱스
24 |
25 | Print(arr);
26 |
27 | // TODO:
28 |
29 | swap(arr[i + 1], arr[hi]);
30 | Print(arr);
31 |
32 | cout << i + 1 << endl; // 피벗 이하인 값들의 마지막 인덱스
33 | }
34 |
--------------------------------------------------------------------------------
/Ex0404_PartitionByPivot/Ex0404_PartitionByPivot.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0405_ExpectedLinearSelection/Ex0405_ExpectedLinearSelection.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0406_WorstcaseLinearSelection/Ex0406_WorstcaseLinearSelection.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0501_RandomizedQuicksort/Ex0501_RandomizedQuicksort.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | using namespace std;
5 |
6 | void Print(vector& arr, int lo, int hi, string sep = "")
7 | {
8 | //cout << "Index: ";
9 | //for (int i = 0; i < arr.size(); i++)
10 | // cout << setfill(' ') << setw(3) << i;
11 | //cout << endl;
12 |
13 | cout << "Value: ";
14 | for (int i = 0; i < arr.size(); i++) {
15 |
16 | if (lo <= i && i <= hi)
17 | cout << setfill(' ') << setw(3) << arr[i] << sep;
18 | else
19 | cout << " ";
20 | }
21 | cout << endl;
22 | }
23 |
24 | int Partition(vector& arr, int lo, int hi)
25 | {
26 | cout << "Pivot = " << arr[hi] << endl;
27 |
28 | int x = arr[hi];
29 | int i = lo - 1;
30 | for (int j = lo; j < hi; j++)
31 | if (arr[j] <= x)
32 | {
33 | i += 1;
34 | swap(arr[i], arr[j]);
35 | }
36 |
37 | swap(arr[i + 1], arr[hi]);
38 |
39 | Print(arr, lo, hi);
40 |
41 | return i + 1; // 피벗이 이동한 위치 반환
42 | }
43 |
44 | int RandomizedPartition(vector& arr, int lo, int hi)
45 | {
46 | int random = lo + rand() % (hi - lo + 1);
47 | swap(arr[random], arr[hi]);
48 | return Partition(arr, lo, hi);
49 | }
50 |
51 | void RandomizedQuicksort(vector& arr, int lo, int hi)
52 | {
53 | Print(arr, lo, hi);
54 |
55 | // TODO:
56 | }
57 |
58 | int main()
59 | {
60 | srand(2);
61 |
62 | vector arr = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
63 |
64 | RandomizedQuicksort(arr, 0, arr.size() - 1);
65 |
66 | Print(arr, 0, arr.size() - 1);
67 |
68 | return 0;
69 | }
70 |
--------------------------------------------------------------------------------
/Ex0501_RandomizedQuicksort/Ex0501_RandomizedQuicksort.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0502_Quick3way/Ex0502_Quick3way.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | using namespace std;
5 |
6 | void Print(vector& arr, int lo, int hi, string sep = "")
7 | {
8 | //cout << "Index: ";
9 | //for (int i = 0; i < arr.size(); i++)
10 | // cout << setfill(' ') << setw(3) << i;
11 | //cout << endl;
12 |
13 | cout << "Value: ";
14 | for (int i = 0; i < arr.size(); i++) {
15 |
16 | if (lo <= i && i <= hi)
17 | cout << setfill(' ') << setw(3) << arr[i] << sep;
18 | else
19 | cout << " ";
20 | }
21 | cout << endl;
22 | }
23 |
24 | // Quicksort with 3-way partitioning, Sedgewick p299
25 | // (Dijkstra's Dutch national flag problem)
26 | void Quick3way(vector& arr, int lo, int hi)
27 | {
28 | if (hi <= lo) return;
29 |
30 | int lt = lo, i = lo + 1, gt = hi;
31 | int v = arr[lo];
32 |
33 | //while (i <= gt)
34 | //{
35 | // // TODO:
36 | //}
37 |
38 | Print(arr, lo, hi);
39 |
40 | //Quick3way(arr, lo, lt - 1);
41 | //Quick3way(arr, gt + 1, hi);
42 | }
43 |
44 | int main()
45 | {
46 | srand(0);
47 |
48 | vector arr = { 3, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 2, 3, 4, 5, 1, 3, 5 };
49 |
50 | Print(arr, 0, arr.size() - 1);
51 |
52 | Quick3way(arr, 0, arr.size() - 1);
53 |
54 | Print(arr, 0, arr.size() - 1);
55 |
56 | return 0;
57 | }
58 |
--------------------------------------------------------------------------------
/Ex0502_Quick3way/Ex0502_Quick3way.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0601_CountingSort/Ex0601_CountingSort.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | using namespace std;
10 |
11 | void Print(vector& arr)
12 | {
13 | for (auto a : arr)
14 | if (a == -1)
15 | cout << "X ";
16 | else
17 | cout << a << " ";
18 | cout << endl;
19 | }
20 |
21 | // 입력은 0 이상 k 이하의 정수, CSLR 8.2
22 | // 결과를 반환하는 구조 (In-place가 아님)
23 | vector CountingSort(const vector& arr, int k)
24 | {
25 | vector count(k + 1, 0); // 0이상 k이하니까 k + 1개를 0으로 초기화
26 |
27 | // TODO:
28 |
29 | cout << "Count: ";
30 | Print(count);
31 |
32 | vector output(arr.size(), -1); // -1로 초기화하는 것은 디버깅용
33 |
34 | // 역순으로 복사
35 | for (int i = output.size() - 1; i >= 0; i--)
36 | {
37 | // TODO:
38 |
39 | cout << "Count: ";
40 | Print(count);
41 |
42 | cout << "Output: ";
43 | Print(output);
44 | }
45 |
46 | return output;
47 | }
48 |
49 | int main()
50 | {
51 | vector arr = { 2, 5, 3, 0, 2, 3, 0, 3 };
52 |
53 | Print(arr);
54 |
55 | int k = *std::max_element(arr.begin(), arr.end());
56 | // 아래 CountingSort()에서 사용할 가장 작은 인덱스(arr에서 가장 작은 값)은 0
57 | // 가장 큰 인덱스(arr에서 가장 큰 값)이 k
58 |
59 | vector result = CountingSort(arr, k);
60 |
61 | Print(result);
62 |
63 | return 0;
64 | }
--------------------------------------------------------------------------------
/Ex0601_CountingSort/Ex0601_CountingSort.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0602_RadixSort/Ex0602_RadixSort.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | using namespace std;
10 |
11 | void Print(vector& arr)
12 | {
13 | for (auto& a : arr)
14 | cout << a << " ";
15 | cout << endl;
16 | }
17 |
18 | // 편의상 결과가 arr에 저장되도록 바꿨습니다.
19 | void CountingSort(vector& arr, int k, int exp)
20 | {
21 | vector temp = arr; // 복사
22 |
23 | vector count(k + 1, 0);
24 | // TODO:
25 |
26 | for (int i = arr.size() - 1; i >= 0; i--)
27 | {
28 | // TODO:
29 | }
30 | }
31 |
32 | void RadixSort(vector& arr)
33 | {
34 | int k = 9; // 0 이상 9 이하
35 | int m = *max_element(arr.begin(), arr.end());
36 |
37 | //for (TODO)
38 | //{
39 | // cout << "exp = " << exp << endl;
40 | // TODO:
41 | // Print(arr);
42 | //}
43 | }
44 |
45 | int main()
46 | {
47 | vector arr = { 170, 45, 75, 90, 802, 24, 2, 66 };
48 | //vector arr = { 2, 5, 3, 0, 2, 3, 0, 3 };
49 |
50 | Print(arr);
51 |
52 | RadixSort(arr);
53 |
54 | return 0;
55 | }
--------------------------------------------------------------------------------
/Ex0602_RadixSort/Ex0602_RadixSort.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0603_SortingWords/Ex0603_SortingWords.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | using namespace std;
11 |
12 | template
13 | void Print(vector& arr)
14 | {
15 | for (auto& a : arr)
16 | cout << a << " ";
17 | cout << endl;
18 | }
19 |
20 | void CountingSort(vector& arr, int k, int d)
21 | {
22 | // vector temp = arr; // 복사
23 | // std::fill(arr.begin(), arr.end(), " "); // 디버깅 편의
24 |
25 | // TODO:
26 | }
27 |
28 | void RadixSort(vector& arr)
29 | {
30 | // TODO:
31 | }
32 |
33 | int main()
34 | {
35 | // CLRS 8.3-1
36 | vector arr = { "COW", "DOG", "SEA", "RUG",
37 | "ROW", "MOB", "BOX", "TAB", "BAR", "EAR", "TAR",
38 | "DIG", "BIG", "TEA", "NOW", "FOX" };
39 |
40 | Print(arr);
41 |
42 | RadixSort(arr);
43 |
44 | Print(arr);
45 |
46 | return 0;
47 | }
--------------------------------------------------------------------------------
/Ex0603_SortingWords/Ex0603_SortingWords.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0604_BucketSort/Ex0604_BucketSort.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | using namespace std;
10 |
11 | void Print(vector& arr)
12 | {
13 | for (auto& a : arr)
14 | cout << a << " ";
15 | cout << endl;
16 | }
17 |
18 | void PrintBuckets(vector>& buckets)
19 | {
20 | for (int i = 0; i < buckets.size(); i++)
21 | {
22 | cout << i << ": ";
23 | for (int j = 0; j < buckets[i].size(); j++)
24 | cout << buckets[i][j] << " ";
25 | cout << endl;
26 | }
27 | }
28 |
29 | // 다른 정렬을 사용해도 됩니다.
30 | void InsertionSort(vector& bucket)
31 | {
32 | for (int i = 1; i < bucket.size(); ++i) {
33 | float key = bucket[i];
34 | int j = i - 1;
35 | while (j >= 0 && bucket[j] > key) {
36 | bucket[j + 1] = bucket[j];
37 | j--;
38 | }
39 | bucket[j + 1] = key;
40 | }
41 | }
42 |
43 | void BucketSort(vector& arr, int num_buckets)
44 | {
45 | vector> buckets(num_buckets);
46 |
47 | // TODO:
48 |
49 | cout << "Before sorting" << endl;
50 | PrintBuckets(buckets);
51 |
52 | // TODO:
53 |
54 | cout << "After sorting" << endl;
55 | PrintBuckets(buckets);
56 |
57 | // TODO:
58 | }
59 |
60 | int main()
61 | {
62 | vector arr = { 0.78f, 0.17f, 0.39f, 0.26f, 0.72f, 0.94f, 0.21f, 0.12f, 0.23f, 0.67f };
63 |
64 | Print(arr);
65 |
66 | BucketSort(arr, 10);
67 |
68 | Print(arr);
69 |
70 | return 0;
71 | }
--------------------------------------------------------------------------------
/Ex0604_BucketSort/Ex0604_BucketSort.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0701_RedBlackTree/Ex0701_RedBlackTree.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0801_SeparateChaining/Ex0801_SeparateChaining.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Ex0802_UnorderedMap/Ex0802_UnorderedMap.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include