├── Chapter02 ├── Problem_2-2 │ └── BubbleSort │ │ ├── BubbleSort.h │ │ ├── BubbleSort.sln │ │ ├── BubbleSort.vcxproj │ │ ├── BubbleSort.vcxproj.filters │ │ └── main.cpp ├── Problem_2-4 │ └── InversionCount │ │ ├── InversionCount.sln │ │ ├── InversionCount.vcxproj │ │ ├── InversionCount.vcxproj.filters │ │ └── main.cpp ├── Section_2.1 │ └── InsertSort │ │ ├── InsertSort.h │ │ ├── InsertSort.sln │ │ ├── InsertSort.vcxproj │ │ ├── InsertSort.vcxproj.filters │ │ └── main.cpp ├── Section_2.2 │ └── SelectSort │ │ ├── SelectSort.h │ │ ├── SelectSort.sln │ │ ├── SelectSort.vcxproj │ │ ├── SelectSort.vcxproj.filters │ │ └── main.cpp └── Section_2.3 │ ├── BinarySearch │ ├── BinarySearch.h │ ├── BinarySearch.sln │ ├── BinarySearch.vcxproj │ ├── BinarySearch.vcxproj.filters │ └── main.cpp │ ├── MergeSort │ ├── MergeSort.h │ ├── MergeSort.sln │ ├── MergeSort.vcxproj │ ├── MergeSort.vcxproj.filters │ └── main.cpp │ └── TwoSum │ ├── MergeSort.h │ ├── TwoSum.sln │ ├── TwoSum.vcxproj │ ├── TwoSum.vcxproj.filters │ └── main.cpp ├── Chapter04 ├── Section_4.1 │ ├── Exercise_4.1-5 │ │ └── MaxSubarray │ │ │ ├── .vs │ │ │ └── MaxSubarray │ │ │ │ └── v16 │ │ │ │ └── .suo │ │ │ ├── MaxSubArray.h │ │ │ ├── MaxSubarray.sln │ │ │ ├── MaxSubarray.vcxproj │ │ │ ├── MaxSubarray.vcxproj.filters │ │ │ ├── MaxSubarray.vcxproj.user │ │ │ └── main.cpp │ └── MaxSubArray │ │ ├── .vs │ │ └── MaxSubArray │ │ │ └── v16 │ │ │ └── .suo │ │ ├── MaxSubArray.h │ │ ├── MaxSubArray.sln │ │ ├── MaxSubArray.vcxproj │ │ ├── MaxSubArray.vcxproj.filters │ │ ├── MaxSubArray.vcxproj.user │ │ └── main.cpp └── Section_4.2 │ └── StrassenSquareMatrixMultiply │ ├── .vs │ └── StrassenSquareMatrixMultiply │ │ └── v16 │ │ └── .suo │ ├── StrassenSquareMatrixMultiply.h │ ├── StrassenSquareMatrixMultiply.sln │ ├── StrassenSquareMatrixMultiply.vcxproj │ ├── StrassenSquareMatrixMultiply.vcxproj.filters │ ├── StrassenSquareMatrixMultiply.vcxproj.user │ └── main.cpp ├── Chapter06 ├── HeapSort │ ├── .vs │ │ └── HeapSort │ │ │ └── v15 │ │ │ └── .suo │ ├── HeapSort.h │ ├── HeapSort.sln │ ├── HeapSort.vcxproj │ ├── HeapSort.vcxproj.filters │ ├── HeapSort.vcxproj.user │ └── main.cpp ├── Problem_6-2 │ └── DMaxHeapDemo │ │ ├── .vs │ │ └── DMaxHeapDemo │ │ │ └── v15 │ │ │ └── .suo │ │ ├── DHeapView.cpp │ │ ├── DHeapView.h │ │ ├── DMaxHeap.h │ │ ├── DMaxHeapDemo.aps │ │ ├── DMaxHeapDemo.cpp │ │ ├── DMaxHeapDemo.h │ │ ├── DMaxHeapDemo.rc │ │ ├── DMaxHeapDemo.sln │ │ ├── DMaxHeapDemo.vcxproj │ │ ├── DMaxHeapDemo.vcxproj.filters │ │ ├── DMaxHeapDemo.vcxproj.user │ │ ├── DMaxHeapDemoDlg.cpp │ │ ├── DMaxHeapDemoDlg.h │ │ ├── res │ │ ├── DMaxHeapDemo.ico │ │ └── DMaxHeapDemo.rc2 │ │ ├── resource.h │ │ ├── stdafx.cpp │ │ ├── stdafx.h │ │ └── targetver.h ├── Problem_6-3 │ └── YoungMatrix │ │ ├── .vs │ │ └── YoungMatrix │ │ │ └── v15 │ │ │ └── .suo │ │ ├── YoungMatrix.aps │ │ ├── YoungMatrix.cpp │ │ ├── YoungMatrix.h │ │ ├── YoungMatrix.rc │ │ ├── YoungMatrix.sln │ │ ├── YoungMatrix.vcxproj │ │ ├── YoungMatrix.vcxproj.filters │ │ ├── YoungMatrix.vcxproj.user │ │ ├── YoungMatrixAlgo.h │ │ ├── YoungMatrixDlg.cpp │ │ ├── YoungMatrixDlg.h │ │ ├── YoungMatrixView.cpp │ │ ├── YoungMatrixView.h │ │ ├── res │ │ ├── YoungMatrix.ico │ │ └── YoungMatrix.rc2 │ │ ├── resource.h │ │ ├── stdafx.cpp │ │ ├── stdafx.h │ │ └── targetver.h └── Section_6.5 │ └── MaxPriorityQueueDemo │ ├── .vs │ └── MaxPriorityQueueDemo │ │ └── v15 │ │ └── .suo │ ├── BinaryHeapView.cpp │ ├── BinaryHeapView.h │ ├── MaxPriorityQueue.h │ ├── MaxPriorityQueueDemo.aps │ ├── MaxPriorityQueueDemo.cpp │ ├── MaxPriorityQueueDemo.h │ ├── MaxPriorityQueueDemo.rc │ ├── MaxPriorityQueueDemo.sln │ ├── MaxPriorityQueueDemo.vcxproj │ ├── MaxPriorityQueueDemo.vcxproj.filters │ ├── MaxPriorityQueueDemo.vcxproj.user │ ├── MaxPriorityQueueDemoDlg.cpp │ ├── MaxPriorityQueueDemoDlg.h │ ├── res │ ├── MaxPriorityQueueDemo.ico │ └── MaxPriorityQueueDemo.rc2 │ ├── resource.h │ ├── stdafx.cpp │ ├── stdafx.h │ └── targetver.h ├── Chapter07 ├── Problem_7-1 │ └── HoareQuickSort │ │ ├── .vs │ │ └── HoareQuickSort │ │ │ └── v15 │ │ │ └── .suo │ │ ├── HoareQuickSort.h │ │ ├── HoareQuickSort.sln │ │ ├── HoareQuickSort.vcxproj │ │ ├── HoareQuickSort.vcxproj.filters │ │ ├── HoareQuickSort.vcxproj.user │ │ └── main.cpp ├── Problem_7-2 │ └── SameElemQuickSort │ │ ├── .vs │ │ └── SameElemQuickSort │ │ │ └── v15 │ │ │ └── .suo │ │ ├── SameElemQuickSort.h │ │ ├── SameElemQuickSort.sln │ │ ├── SameElemQuickSort.vcxproj │ │ ├── SameElemQuickSort.vcxproj.filters │ │ ├── SameElemQuickSort.vcxproj.user │ │ └── main.cpp ├── Problem_7-4 │ └── TailRecursiveQuicksort │ │ ├── .vs │ │ └── TailRecursiveQuicksort │ │ │ └── v15 │ │ │ └── .suo │ │ ├── TailRecursiveQuicksort.h │ │ ├── TailRecursiveQuicksort.sln │ │ ├── TailRecursiveQuicksort.vcxproj │ │ ├── TailRecursiveQuicksort.vcxproj.filters │ │ ├── TailRecursiveQuicksort.vcxproj.user │ │ └── main.cpp └── Section_7.1 │ └── QuickSort │ ├── .vs │ └── QuickSort │ │ └── v15 │ │ └── .suo │ ├── QuickSort.h │ ├── QuickSort.sln │ ├── QuickSort.vcxproj │ ├── QuickSort.vcxproj.filters │ ├── QuickSort.vcxproj.user │ └── main.cpp ├── Chapter08 ├── Problem_8-2 │ └── InPlaceCourtingSort │ │ ├── .vs │ │ └── InPlaceCourtingSort │ │ │ └── v16 │ │ │ └── .suo │ │ ├── InPlaceCountingSort.h │ │ ├── InPlaceCourtingSort.sln │ │ ├── InPlaceCourtingSort.vcxproj │ │ ├── InPlaceCourtingSort.vcxproj.filters │ │ ├── InPlaceCourtingSort.vcxproj.user │ │ └── main.cpp ├── Problem_8-3 │ ├── a │ │ └── RadixSortUnfixedLengthItems │ │ │ ├── .vs │ │ │ └── RadixSortUnfixedLengthItems │ │ │ │ └── v16 │ │ │ │ └── .suo │ │ │ ├── RadixSortUnfixedLengthItems.h │ │ │ ├── RadixSortUnfixedLengthItems.sln │ │ │ ├── RadixSortUnfixedLengthItems.vcxproj │ │ │ ├── RadixSortUnfixedLengthItems.vcxproj.filters │ │ │ ├── RadixSortUnfixedLengthItems.vcxproj.user │ │ │ └── main.cpp │ └── b │ │ └── SortString │ │ ├── .vs │ │ └── SortString │ │ │ └── v16 │ │ │ └── .suo │ │ ├── SortString.cpp │ │ ├── SortString.h │ │ ├── SortString.sln │ │ ├── SortString.vcxproj │ │ ├── SortString.vcxproj.filters │ │ ├── SortString.vcxproj.user │ │ └── main.cpp ├── Section_8.2 │ └── CountingSort │ │ ├── .vs │ │ └── CountingSort │ │ │ └── v16 │ │ │ └── .suo │ │ ├── CountingSort.h │ │ ├── CountingSort.sln │ │ ├── CountingSort.vcxproj │ │ ├── CountingSort.vcxproj.filters │ │ ├── CountingSort.vcxproj.user │ │ └── main.cpp ├── Section_8.3 │ └── RadixSort │ │ ├── .vs │ │ └── RadixSort │ │ │ └── v16 │ │ │ └── .suo │ │ ├── RadixSort.h │ │ ├── RadixSort.sln │ │ ├── RadixSort.vcxproj │ │ ├── RadixSort.vcxproj.filters │ │ ├── RadixSort.vcxproj.user │ │ └── main.cpp └── Section_8.4 │ └── BucketSort │ ├── .vs │ └── BucketSort │ │ └── v16 │ │ └── .suo │ ├── BucketSort.h │ ├── BucketSort.sln │ ├── BucketSort.vcxproj │ ├── BucketSort.vcxproj.filters │ ├── LinkedList.h │ └── main.cpp ├── Chapter09 └── Section_9.1 │ ├── Exercise_9.1-1 │ └── FindSecondMin │ │ ├── .vs │ │ └── FindSecondMin │ │ │ └── v16 │ │ │ └── .suo │ │ ├── FindSecondMin.h │ │ ├── FindSecondMin.sln │ │ ├── FindSecondMin.vcxproj │ │ ├── FindSecondMin.vcxproj.filters │ │ ├── FindSecondMin.vcxproj.user │ │ └── main.cpp │ ├── Exercise_9.1-2 │ └── FindMinMaxRandom │ │ ├── .vs │ │ └── FindMinMaxRandom │ │ │ ├── FileContentIndex │ │ │ ├── 6e270b03-c3af-4078-8d84-c35c2686f6ab.vsidx │ │ │ ├── c345ef06-7cca-4928-8520-ce952861cc38.vsidx │ │ │ └── read.lock │ │ │ └── v17 │ │ │ └── .suo │ │ ├── FindMinMaxRandom.sln │ │ ├── FindMinMaxRandom.vcxproj │ │ ├── FindMinMaxRandom.vcxproj.filters │ │ ├── FindMinMaxRandom.vcxproj.user │ │ └── main.cpp │ └── FindMinMax │ ├── .vs │ └── FindMinMax │ │ └── v16 │ │ └── .suo │ ├── FindMinMax.h │ ├── FindMinMax.sln │ ├── FindMinMax.vcxproj │ ├── FindMinMax.vcxproj.filters │ ├── FindMinMax.vcxproj.user │ └── main.cpp ├── Chapter15 ├── Problems │ ├── Problem_15-10 │ │ └── InvestPlanDemo │ │ │ ├── .vs │ │ │ └── InvestPlanDemo │ │ │ │ └── v15 │ │ │ │ └── .suo │ │ │ ├── InvestPlanAlgo.cpp │ │ │ ├── InvestPlanAlgo.h │ │ │ ├── InvestPlanDemo.aps │ │ │ ├── InvestPlanDemo.cpp │ │ │ ├── InvestPlanDemo.h │ │ │ ├── InvestPlanDemo.rc │ │ │ ├── InvestPlanDemo.sln │ │ │ ├── InvestPlanDemo.vcxproj │ │ │ ├── InvestPlanDemo.vcxproj.filters │ │ │ ├── InvestPlanDemo.vcxproj.user │ │ │ ├── InvestPlanDemoDlg.cpp │ │ │ ├── InvestPlanDemoDlg.h │ │ │ ├── InvestPlanView.cpp │ │ │ ├── InvestPlanView.h │ │ │ ├── res │ │ │ ├── InvestPlanDemo.ico │ │ │ └── InvestPlanDemo.rc2 │ │ │ ├── resource.h │ │ │ ├── stdafx.cpp │ │ │ ├── stdafx.h │ │ │ └── targetver.h │ ├── Problem_15-2 │ │ └── LPS │ │ │ ├── .vs │ │ │ └── LPS │ │ │ │ └── v15 │ │ │ │ └── .suo │ │ │ ├── LPS.sln │ │ │ ├── LPS.vcxproj │ │ │ ├── LPS.vcxproj.filters │ │ │ └── main.cpp │ ├── Problem_15-3 │ │ └── MinBitonicPath │ │ │ ├── .vs │ │ │ └── MinBitonicPath │ │ │ │ └── v15 │ │ │ │ └── .suo │ │ │ ├── MinBitonicPath.aps │ │ │ ├── MinBitonicPath.cpp │ │ │ ├── MinBitonicPath.h │ │ │ ├── MinBitonicPath.rc │ │ │ ├── MinBitonicPath.sln │ │ │ ├── MinBitonicPath.vcxproj │ │ │ ├── MinBitonicPath.vcxproj.filters │ │ │ ├── MinBitonicPath.vcxproj.user │ │ │ ├── MinBitonicPathAlgo.cpp │ │ │ ├── MinBitonicPathAlgo.h │ │ │ ├── MinBitonicPathDlg.cpp │ │ │ ├── MinBitonicPathDlg.h │ │ │ ├── MinBitonicPathView.cpp │ │ │ ├── MinBitonicPathView.h │ │ │ ├── res │ │ │ ├── MinBitonicPath.ico │ │ │ └── MinBitonicPath.rc2 │ │ │ ├── resource.h │ │ │ ├── stdafx.cpp │ │ │ ├── stdafx.h │ │ │ └── targetver.h │ ├── Problem_15-4 │ │ └── NeatlyPrint │ │ │ ├── .vs │ │ │ └── NeatlyPrint │ │ │ │ └── v15 │ │ │ │ └── .suo │ │ │ ├── NeatlyPrint.sln │ │ │ ├── NeatlyPrint.vcxproj │ │ │ ├── NeatlyPrint.vcxproj.filters │ │ │ ├── NeatlyPrint.vcxproj.user │ │ │ ├── NeatlyPrintAlgo.cpp │ │ │ ├── NeatlyPrintAlgo.h │ │ │ ├── input.txt │ │ │ └── main.cpp │ ├── Problem_15-5 │ │ ├── DNAAlign │ │ │ ├── .vs │ │ │ │ └── DNAAlign │ │ │ │ │ └── v15 │ │ │ │ │ └── .suo │ │ │ ├── DNAAlign.sln │ │ │ ├── DNAAlign.vcxproj │ │ │ ├── DNAAlign.vcxproj.filters │ │ │ ├── DNAAlign.vcxproj.user │ │ │ └── main.cpp │ │ └── EditDistance │ │ │ ├── .vs │ │ │ └── EditDistance │ │ │ │ └── v15 │ │ │ │ └── .suo │ │ │ ├── EditDistance.aps │ │ │ ├── EditDistance.cpp │ │ │ ├── EditDistance.h │ │ │ ├── EditDistance.rc │ │ │ ├── EditDistance.sln │ │ │ ├── EditDistance.vcxproj │ │ │ ├── EditDistance.vcxproj.filters │ │ │ ├── EditDistance.vcxproj.user │ │ │ ├── EditDistanceAlgo.cpp │ │ │ ├── EditDistanceAlgo.h │ │ │ ├── EditDistanceDlg.cpp │ │ │ ├── EditDistanceDlg.h │ │ │ ├── TransferView.cpp │ │ │ ├── TransferView.h │ │ │ ├── res │ │ │ ├── EditDistance.ico │ │ │ └── EditDistance.rc2 │ │ │ ├── resource.h │ │ │ ├── stdafx.cpp │ │ │ ├── stdafx.h │ │ │ └── targetver.h │ ├── Problem_15-8 │ │ └── ImageSeamDemo │ │ │ ├── .vs │ │ │ └── ImageSeamDemo │ │ │ │ └── v15 │ │ │ │ └── .suo │ │ │ ├── CImageSeamView.cpp │ │ │ ├── CImageSeamView.h │ │ │ ├── ImageSeam.cpp │ │ │ ├── ImageSeam.h │ │ │ ├── ImageSeamDemo.aps │ │ │ ├── ImageSeamDemo.cpp │ │ │ ├── ImageSeamDemo.h │ │ │ ├── ImageSeamDemo.rc │ │ │ ├── ImageSeamDemo.sln │ │ │ ├── ImageSeamDemo.vcxproj │ │ │ ├── ImageSeamDemo.vcxproj.filters │ │ │ ├── ImageSeamDemo.vcxproj.user │ │ │ ├── ImageSeamDemoDlg.cpp │ │ │ ├── ImageSeamDemoDlg.h │ │ │ ├── res │ │ │ ├── ImageSeamDemo.ico │ │ │ └── ImageSeamDemo.rc2 │ │ │ ├── resource.h │ │ │ ├── stdafx.cpp │ │ │ ├── stdafx.h │ │ │ └── targetver.h │ └── Problem_15-9 │ │ └── StringSplitDemo │ │ ├── .vs │ │ └── StringSplitDemo │ │ │ └── v15 │ │ │ └── .suo │ │ ├── StringSplitAlgo.cpp │ │ ├── StringSplitAlgo.h │ │ ├── StringSplitDemo.sln │ │ ├── StringSplitDemo.vcxproj │ │ ├── StringSplitDemo.vcxproj.filters │ │ ├── StringSplitDemo.vcxproj.user │ │ └── main.cpp ├── Section_15.1 │ └── RodCut │ │ ├── .vs │ │ └── RodCut │ │ │ └── v15 │ │ │ └── .suo │ │ ├── RodCut.sln │ │ ├── RodCut.vcxproj │ │ ├── RodCut.vcxproj.filters │ │ └── main.cpp ├── Section_15.2 │ └── MatrixChainOrder │ │ ├── .vs │ │ └── MatrixChainOrder │ │ │ └── v15 │ │ │ └── .suo │ │ ├── MatrixChainOrder.sln │ │ ├── MatrixChainOrder.vcxproj │ │ ├── MatrixChainOrder.vcxproj.filters │ │ └── main.cpp ├── Section_15.4 │ ├── Exercise_15.4-6 │ │ └── LMIS │ │ │ ├── .vs │ │ │ └── LMIS │ │ │ │ └── v15 │ │ │ │ └── .suo │ │ │ ├── LMIS.sln │ │ │ ├── LMIS.vcxproj │ │ │ ├── LMIS.vcxproj.filters │ │ │ └── main.cpp │ └── LCS │ │ ├── .vs │ │ └── LCS │ │ │ └── v15 │ │ │ └── .suo │ │ ├── LCS.sln │ │ ├── LCS.vcxproj │ │ ├── LCS.vcxproj.filters │ │ └── main.cpp └── Section_15.5 │ └── OptimalBST │ ├── .vs │ └── OptimalBST │ │ └── v15 │ │ └── .suo │ ├── BinarySearchTree.h │ ├── BinaryTree.h │ ├── OptimalBST.aps │ ├── OptimalBST.cpp │ ├── OptimalBST.h │ ├── OptimalBST.rc │ ├── OptimalBST.sln │ ├── OptimalBST.vcxproj │ ├── OptimalBST.vcxproj.filters │ ├── OptimalBST.vcxproj.user │ ├── OptimalBSTDlg.cpp │ ├── OptimalBSTDlg.h │ ├── OptimalBSTView.cpp │ ├── OptimalBSTView.h │ ├── OptimalBinarySearchTree.cpp │ ├── OptimalBinarySearchTree.h │ ├── res │ ├── OptimalBST.ico │ ├── OptimalBST.rc2 │ ├── Toolbar.bmp │ └── Toolbar256.bmp │ ├── resource.h │ ├── stdafx.cpp │ ├── stdafx.h │ └── targetver.h └── Others └── ComparisonSort ├── 1.bmp ├── 2.bmp ├── 3.bmp ├── 4.bmp ├── Sort.h └── main.cpp /Chapter02/Problem_2-2/BubbleSort/BubbleSort.h: -------------------------------------------------------------------------------- 1 | #ifndef _BUBBLE_SORT_H_ 2 | #define _BUBBLE_SORT_H_ 3 | 4 | template 5 | inline void swap(T &x, T &y) 6 | { 7 | if(&x != &y) 8 | { 9 | T tmp = x; 10 | x = y; 11 | y = tmp; 12 | } 13 | } 14 | 15 | template 16 | void bubble_sort(T data[], int n) 17 | { 18 | if(data != NULL) 19 | { 20 | for(int i = 0; i < n-1; ++i) 21 | { 22 | for(int j = n-1; j > i; --j) 23 | if(data[j] < data[j-1]) 24 | swap(data[j], data[j-1]); 25 | } 26 | } 27 | } 28 | 29 | #endif // #ifndef _BUBBLE_SORT_H_ 30 | -------------------------------------------------------------------------------- /Chapter02/Problem_2-2/BubbleSort/BubbleSort.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BubbleSort", "BubbleSort.vcxproj", "{3BFB875C-0906-4BAA-98B8-909C538A8879}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {3BFB875C-0906-4BAA-98B8-909C538A8879}.Debug|x64.ActiveCfg = Debug|x64 17 | {3BFB875C-0906-4BAA-98B8-909C538A8879}.Debug|x64.Build.0 = Debug|x64 18 | {3BFB875C-0906-4BAA-98B8-909C538A8879}.Debug|x86.ActiveCfg = Debug|Win32 19 | {3BFB875C-0906-4BAA-98B8-909C538A8879}.Debug|x86.Build.0 = Debug|Win32 20 | {3BFB875C-0906-4BAA-98B8-909C538A8879}.Release|x64.ActiveCfg = Release|x64 21 | {3BFB875C-0906-4BAA-98B8-909C538A8879}.Release|x64.Build.0 = Release|x64 22 | {3BFB875C-0906-4BAA-98B8-909C538A8879}.Release|x86.ActiveCfg = Release|Win32 23 | {3BFB875C-0906-4BAA-98B8-909C538A8879}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {36809878-8352-4996-BFC2-FC4F1D01F1FD} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter02/Problem_2-2/BubbleSort/BubbleSort.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter02/Problem_2-2/BubbleSort/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "BubbleSort.h" 3 | 4 | using namespace std; 5 | 6 | template 7 | void PrintArray(T data[], int n) 8 | { 9 | if(data != NULL) 10 | { 11 | for(int i = 0; i < n; ++i) 12 | cout << data[i] << "\t"; 13 | } 14 | } 15 | 16 | int main() 17 | { 18 | int a1[] = {3, 2}; 19 | bubble_sort(a1, sizeof(a1)/sizeof(int)); 20 | PrintArray(a1, sizeof(a1)/sizeof(int)); 21 | cout << "\n"; 22 | 23 | int a2[] = {5, 4, 3, 2, 1}; 24 | bubble_sort(a2, sizeof(a2)/sizeof(int)); 25 | PrintArray(a2, sizeof(a2)/sizeof(int)); 26 | cout << "\n"; 27 | 28 | int a3[] = {5, 4, 3, 2, 1, 5, 7, 4, 3, 5}; 29 | bubble_sort(a3, sizeof(a3)/sizeof(int)); 30 | PrintArray(a3, sizeof(a3)/sizeof(int)); 31 | cout << "\n"; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Chapter02/Problem_2-4/InversionCount/InversionCount.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "InversionCount", "InversionCount.vcxproj", "{12E1AE5C-05CE-4E33-8545-2E1FB0FB2881}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {12E1AE5C-05CE-4E33-8545-2E1FB0FB2881}.Debug|x64.ActiveCfg = Debug|x64 17 | {12E1AE5C-05CE-4E33-8545-2E1FB0FB2881}.Debug|x64.Build.0 = Debug|x64 18 | {12E1AE5C-05CE-4E33-8545-2E1FB0FB2881}.Debug|x86.ActiveCfg = Debug|Win32 19 | {12E1AE5C-05CE-4E33-8545-2E1FB0FB2881}.Debug|x86.Build.0 = Debug|Win32 20 | {12E1AE5C-05CE-4E33-8545-2E1FB0FB2881}.Release|x64.ActiveCfg = Release|x64 21 | {12E1AE5C-05CE-4E33-8545-2E1FB0FB2881}.Release|x64.Build.0 = Release|x64 22 | {12E1AE5C-05CE-4E33-8545-2E1FB0FB2881}.Release|x86.ActiveCfg = Release|Win32 23 | {12E1AE5C-05CE-4E33-8545-2E1FB0FB2881}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {4EEF82BC-A499-4448-AB53-E0512E694A5B} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter02/Problem_2-4/InversionCount/InversionCount.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter02/Problem_2-4/InversionCount/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define _PRINT_INVERSION_ 6 | 7 | void merge(int data[], int temp[], int left, int mid, int right) 8 | { 9 | for(int i = left; i <= right; ++i) 10 | temp[i] = data[i]; 11 | 12 | int i = left; 13 | int j = mid + 1; 14 | int k = left; 15 | 16 | while(i <= mid) 17 | { 18 | if(j <= right) 19 | { 20 | if(temp[i] <= temp[j]) 21 | data[k++] = temp[i++]; 22 | else 23 | data[k++] = temp[j++]; 24 | } 25 | else 26 | { 27 | data[k++] = temp[i++]; 28 | } 29 | } 30 | 31 | while(j <= right) 32 | data[k++] = temp[j++]; 33 | } 34 | 35 | int CrossInversionCount(int data[], int left, int mid, int right) 36 | { 37 | int i = left; 38 | int j = mid + 1; 39 | int count = 0; 40 | 41 | while(i <= mid && j <= right) 42 | { 43 | if(data[i] > data[j]) 44 | { 45 | #ifdef _PRINT_INVERSION_ 46 | for(int k = i; k <= mid; ++k) 47 | cout << "(" << data[k] << ", " << data[j] << ")\n"; 48 | #endif // #ifdef _PRINT_INVERSION_ 49 | 50 | count += (mid-i+1); 51 | j++; 52 | } 53 | else 54 | { 55 | i++; 56 | } 57 | } 58 | 59 | return count; 60 | } 61 | 62 | int InversionCount(int data[], int temp[], int left, int right) 63 | { 64 | int count = 0; 65 | 66 | if(left < right) 67 | { 68 | int mid = (left+right)/2; 69 | count += InversionCount(data, temp, left, mid); 70 | count += InversionCount(data, temp, mid+1, right); 71 | count += CrossInversionCount(data, left, mid, right); 72 | merge(data, temp, left, mid, right); 73 | } 74 | 75 | return count; 76 | } 77 | 78 | int InversionCount(int data[], int n) 79 | { 80 | int count = 0; 81 | 82 | if(data != NULL && n > 1) 83 | { 84 | int *temp = new int[n]; 85 | count = InversionCount(data, temp, 0, n-1); 86 | delete[] temp; 87 | } 88 | 89 | return count; 90 | } 91 | 92 | int main() 93 | { 94 | int a1[] = {2, 3, 8, 6, 1}; 95 | cout << "Inversion Count: " << InversionCount(a1, sizeof(a1)/sizeof(int)) << "\n"; 96 | } 97 | -------------------------------------------------------------------------------- /Chapter02/Section_2.1/InsertSort/InsertSort.h: -------------------------------------------------------------------------------- 1 | #ifndef _INSERT_SORT_H_ 2 | #define _INSERT_SORT_H_ 3 | 4 | template 5 | void insert_sort(T data[], int n) 6 | { 7 | if(data != NULL && n > 1) 8 | { 9 | for(int i = 1; i < n; ++i) 10 | { 11 | T key = data[i]; 12 | 13 | int j; 14 | for(j = i-1; j >= 0 && data[j] > key; --j) 15 | data[j+1] = data[j]; 16 | 17 | data[j+1] = key; 18 | } 19 | } 20 | } 21 | 22 | #endif // #ifndef _INSERT_SORT_H_ 23 | -------------------------------------------------------------------------------- /Chapter02/Section_2.1/InsertSort/InsertSort.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "InsertSort", "InsertSort.vcxproj", "{F071BF02-A0C1-49B9-B8FE-BE3323C700F8}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {F071BF02-A0C1-49B9-B8FE-BE3323C700F8}.Debug|x64.ActiveCfg = Debug|x64 17 | {F071BF02-A0C1-49B9-B8FE-BE3323C700F8}.Debug|x64.Build.0 = Debug|x64 18 | {F071BF02-A0C1-49B9-B8FE-BE3323C700F8}.Debug|x86.ActiveCfg = Debug|Win32 19 | {F071BF02-A0C1-49B9-B8FE-BE3323C700F8}.Debug|x86.Build.0 = Debug|Win32 20 | {F071BF02-A0C1-49B9-B8FE-BE3323C700F8}.Release|x64.ActiveCfg = Release|x64 21 | {F071BF02-A0C1-49B9-B8FE-BE3323C700F8}.Release|x64.Build.0 = Release|x64 22 | {F071BF02-A0C1-49B9-B8FE-BE3323C700F8}.Release|x86.ActiveCfg = Release|Win32 23 | {F071BF02-A0C1-49B9-B8FE-BE3323C700F8}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {5B89691F-9E45-4F59-9B54-E0EA2C64A3D2} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter02/Section_2.1/InsertSort/InsertSort.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter02/Section_2.1/InsertSort/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "InsertSort.h" 3 | 4 | using namespace std; 5 | 6 | template 7 | void PrintArray(T data[], int n) 8 | { 9 | if(data != NULL) 10 | { 11 | for(int i = 0; i < n; ++i) 12 | cout << data[i] << "\t"; 13 | } 14 | } 15 | 16 | int main() 17 | { 18 | int a1[] = {3, 2}; 19 | insert_sort(a1, sizeof(a1)/sizeof(int)); 20 | PrintArray(a1, sizeof(a1)/sizeof(int)); 21 | cout << "\n"; 22 | 23 | int a2[] = {5, 4, 3, 2, 1}; 24 | insert_sort(a2, sizeof(a2)/sizeof(int)); 25 | PrintArray(a2, sizeof(a2)/sizeof(int)); 26 | cout << "\n"; 27 | 28 | int a3[] = {5, 4, 3, 2, 1, 5, 7, 4, 3, 5}; 29 | insert_sort(a3, sizeof(a3)/sizeof(int)); 30 | PrintArray(a3, sizeof(a3)/sizeof(int)); 31 | cout << "\n"; 32 | } 33 | -------------------------------------------------------------------------------- /Chapter02/Section_2.2/SelectSort/SelectSort.h: -------------------------------------------------------------------------------- 1 | #ifndef _SELECT_SORT_H_ 2 | #define _SELECT_SORT_H_ 3 | 4 | template 5 | inline void swap(T &x, T &y) 6 | { 7 | if(&x != &y) 8 | { 9 | T tmp = x; 10 | x = y; 11 | y = tmp; 12 | } 13 | } 14 | 15 | template 16 | void select_sort(T data[], int n) 17 | { 18 | if(data != NULL && n > 1) 19 | { 20 | for(int i = 0; i < n-1; ++i) 21 | { 22 | int minIndex = i; 23 | 24 | for(int j = i+1; j < n; ++j) 25 | if(data[j] < data[minIndex]) 26 | minIndex = j; 27 | 28 | swap(data[i], data[minIndex]); 29 | } 30 | } 31 | } 32 | 33 | #endif // #ifndef _SELECT_SORT_H_ 34 | -------------------------------------------------------------------------------- /Chapter02/Section_2.2/SelectSort/SelectSort.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SelectSort", "SelectSort.vcxproj", "{9C07705B-6E47-4479-9518-3DFC215B9E23}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {9C07705B-6E47-4479-9518-3DFC215B9E23}.Debug|x64.ActiveCfg = Debug|x64 17 | {9C07705B-6E47-4479-9518-3DFC215B9E23}.Debug|x64.Build.0 = Debug|x64 18 | {9C07705B-6E47-4479-9518-3DFC215B9E23}.Debug|x86.ActiveCfg = Debug|Win32 19 | {9C07705B-6E47-4479-9518-3DFC215B9E23}.Debug|x86.Build.0 = Debug|Win32 20 | {9C07705B-6E47-4479-9518-3DFC215B9E23}.Release|x64.ActiveCfg = Release|x64 21 | {9C07705B-6E47-4479-9518-3DFC215B9E23}.Release|x64.Build.0 = Release|x64 22 | {9C07705B-6E47-4479-9518-3DFC215B9E23}.Release|x86.ActiveCfg = Release|Win32 23 | {9C07705B-6E47-4479-9518-3DFC215B9E23}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {93FE2AF9-0BDE-4C83-BF3A-56D15063D25B} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter02/Section_2.2/SelectSort/SelectSort.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter02/Section_2.2/SelectSort/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SelectSort.h" 3 | 4 | using namespace std; 5 | 6 | template 7 | void PrintArray(T data[], int n) 8 | { 9 | if(data != NULL) 10 | { 11 | for(int i = 0; i < n; ++i) 12 | cout << data[i] << "\t"; 13 | } 14 | } 15 | 16 | int main() 17 | { 18 | int a1[] = {3, 2}; 19 | select_sort(a1, sizeof(a1)/sizeof(int)); 20 | PrintArray(a1, sizeof(a1)/sizeof(int)); 21 | cout << "\n"; 22 | 23 | int a2[] = {5, 4, 3, 2, 1}; 24 | select_sort(a2, sizeof(a2)/sizeof(int)); 25 | PrintArray(a2, sizeof(a2)/sizeof(int)); 26 | cout << "\n"; 27 | 28 | int a3[] = {5, 4, 3, 2, 1, 5, 7, 4, 3, 5}; 29 | select_sort(a3, sizeof(a3)/sizeof(int)); 30 | PrintArray(a3, sizeof(a3)/sizeof(int)); 31 | cout << "\n"; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Chapter02/Section_2.3/BinarySearch/BinarySearch.h: -------------------------------------------------------------------------------- 1 | #ifndef _BINARY_SEARCH_H_ 2 | #define _BINARY_SEARCH_H_ 3 | 4 | template 5 | int binary_search(T data[], int n, const T &v) 6 | { 7 | if(data != NULL && n > 0) 8 | { 9 | int left = 0; 10 | int right = n-1; 11 | 12 | while(left <= right) 13 | { 14 | int mid = (left+right)/2; 15 | 16 | if(v < data[mid]) 17 | right = mid - 1; 18 | else if(v > data[mid]) 19 | left = mid + 1; 20 | else 21 | return mid; 22 | } 23 | } 24 | 25 | return -1; 26 | } 27 | 28 | #endif // #ifndef _BINARY_SEARCH_H_ 29 | -------------------------------------------------------------------------------- /Chapter02/Section_2.3/BinarySearch/BinarySearch.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BinarySearch", "BinarySearch.vcxproj", "{46EE7EA1-5FD0-4FB3-BDFB-5EB9BFD438CA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {46EE7EA1-5FD0-4FB3-BDFB-5EB9BFD438CA}.Debug|x64.ActiveCfg = Debug|x64 17 | {46EE7EA1-5FD0-4FB3-BDFB-5EB9BFD438CA}.Debug|x64.Build.0 = Debug|x64 18 | {46EE7EA1-5FD0-4FB3-BDFB-5EB9BFD438CA}.Debug|x86.ActiveCfg = Debug|Win32 19 | {46EE7EA1-5FD0-4FB3-BDFB-5EB9BFD438CA}.Debug|x86.Build.0 = Debug|Win32 20 | {46EE7EA1-5FD0-4FB3-BDFB-5EB9BFD438CA}.Release|x64.ActiveCfg = Release|x64 21 | {46EE7EA1-5FD0-4FB3-BDFB-5EB9BFD438CA}.Release|x64.Build.0 = Release|x64 22 | {46EE7EA1-5FD0-4FB3-BDFB-5EB9BFD438CA}.Release|x86.ActiveCfg = Release|Win32 23 | {46EE7EA1-5FD0-4FB3-BDFB-5EB9BFD438CA}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {8EFF4452-BFA5-4E80-B326-1685552D4796} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter02/Section_2.3/BinarySearch/BinarySearch.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter02/Section_2.3/BinarySearch/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "BinarySearch.h" 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int a1[] = {1, 3, 5, 7, 9, 11}; 9 | cout << binary_search(a1, sizeof(a1)/sizeof(int), 3) << "\n"; 10 | } 11 | -------------------------------------------------------------------------------- /Chapter02/Section_2.3/MergeSort/MergeSort.h: -------------------------------------------------------------------------------- 1 | #ifndef _MERGE_SORT_H_ 2 | #define _MERGE_SORT_H_ 3 | 4 | template 5 | void merge(T data[], T temp[], int left, int mid, int right) 6 | { 7 | for(int i = left; i <= right; ++i) 8 | temp[i] = data[i]; 9 | 10 | int i = left; 11 | int j = mid + 1; 12 | int k = left; 13 | 14 | while(i <= mid) 15 | { 16 | if(j <= right) 17 | { 18 | if(temp[i] <= temp[j]) 19 | data[k++] = temp[i++]; 20 | else 21 | data[k++] = temp[j++]; 22 | } 23 | else 24 | { 25 | data[k++] = temp[i++]; 26 | } 27 | } 28 | 29 | while(j <= right) 30 | data[k++] = temp[j++]; 31 | } 32 | 33 | template 34 | void merge_sort(T data[], T temp[], int left, int right) 35 | { 36 | if(left < right) 37 | { 38 | int mid = (left+right)/2; 39 | merge_sort(data, temp, left, mid); 40 | merge_sort(data, temp, mid+1, right); 41 | merge(data, temp, left, mid, right); 42 | } 43 | } 44 | 45 | template 46 | void merge_sort(T data[], int n) 47 | { 48 | if(data != NULL && n > 1) 49 | { 50 | T *temp = new T[n]; 51 | merge_sort(data, temp, 0, n-1); 52 | delete[] temp; 53 | } 54 | } 55 | 56 | #endif // #ifndef _MERGE_SORT_H_ 57 | -------------------------------------------------------------------------------- /Chapter02/Section_2.3/MergeSort/MergeSort.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MergeSort", "MergeSort.vcxproj", "{AE049890-DC98-4C94-AA1F-4CD42B5E342D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {AE049890-DC98-4C94-AA1F-4CD42B5E342D}.Debug|x64.ActiveCfg = Debug|x64 17 | {AE049890-DC98-4C94-AA1F-4CD42B5E342D}.Debug|x64.Build.0 = Debug|x64 18 | {AE049890-DC98-4C94-AA1F-4CD42B5E342D}.Debug|x86.ActiveCfg = Debug|Win32 19 | {AE049890-DC98-4C94-AA1F-4CD42B5E342D}.Debug|x86.Build.0 = Debug|Win32 20 | {AE049890-DC98-4C94-AA1F-4CD42B5E342D}.Release|x64.ActiveCfg = Release|x64 21 | {AE049890-DC98-4C94-AA1F-4CD42B5E342D}.Release|x64.Build.0 = Release|x64 22 | {AE049890-DC98-4C94-AA1F-4CD42B5E342D}.Release|x86.ActiveCfg = Release|Win32 23 | {AE049890-DC98-4C94-AA1F-4CD42B5E342D}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {DD9615C1-02B0-4BAC-8AD7-8356C9FB2F8F} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter02/Section_2.3/MergeSort/MergeSort.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter02/Section_2.3/MergeSort/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "MergeSort.h" 3 | 4 | using namespace std; 5 | 6 | template 7 | void PrintArray(T data[], int n) 8 | { 9 | if(data != NULL) 10 | { 11 | for(int i = 0; i < n; ++i) 12 | cout << data[i] << "\t"; 13 | } 14 | } 15 | 16 | int main() 17 | { 18 | int a1[] = {3, 2}; 19 | merge_sort(a1, sizeof(a1)/sizeof(int)); 20 | PrintArray(a1, sizeof(a1)/sizeof(int)); 21 | cout << "\n"; 22 | 23 | int a2[] = {5, 4, 3, 2, 1}; 24 | merge_sort(a2, sizeof(a2)/sizeof(int)); 25 | PrintArray(a2, sizeof(a2)/sizeof(int)); 26 | cout << "\n"; 27 | 28 | int a3[] = {5, 4, 3, 2, 1, 5, 7, 4, 3, 5}; 29 | merge_sort(a3, sizeof(a3)/sizeof(int)); 30 | PrintArray(a3, sizeof(a3)/sizeof(int)); 31 | cout << "\n"; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Chapter02/Section_2.3/TwoSum/MergeSort.h: -------------------------------------------------------------------------------- 1 | #ifndef _MERGE_SORT_H_ 2 | #define _MERGE_SORT_H_ 3 | 4 | template 5 | void merge(T data[], T temp[], int left, int mid, int right) 6 | { 7 | for(int i = left; i <= right; ++i) 8 | temp[i] = data[i]; 9 | 10 | int i = left; 11 | int j = mid + 1; 12 | int k = left; 13 | 14 | while(i <= mid) 15 | { 16 | if(j <= right) 17 | { 18 | if(temp[i] <= temp[j]) 19 | data[k++] = temp[i++]; 20 | else 21 | data[k++] = temp[j++]; 22 | } 23 | else 24 | { 25 | data[k++] = temp[i++]; 26 | } 27 | } 28 | 29 | while(j <= right) 30 | data[k++] = temp[j++]; 31 | } 32 | 33 | template 34 | void merge_sort(T data[], T temp[], int left, int right) 35 | { 36 | if(left < right) 37 | { 38 | int mid = (left+right)/2; 39 | merge_sort(data, temp, left, mid); 40 | merge_sort(data, temp, mid+1, right); 41 | merge(data, temp, left, mid, right); 42 | } 43 | } 44 | 45 | template 46 | void merge_sort(T data[], int n) 47 | { 48 | if(data != NULL && n > 1) 49 | { 50 | T *temp = new T[n]; 51 | merge_sort(data, temp, 0, n-1); 52 | delete[] temp; 53 | } 54 | } 55 | 56 | #endif // #ifndef _MERGE_SORT_H_ 57 | -------------------------------------------------------------------------------- /Chapter02/Section_2.3/TwoSum/TwoSum.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TwoSum", "TwoSum.vcxproj", "{617DB37E-D385-450F-9287-21FCF840942A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {617DB37E-D385-450F-9287-21FCF840942A}.Debug|x64.ActiveCfg = Debug|x64 17 | {617DB37E-D385-450F-9287-21FCF840942A}.Debug|x64.Build.0 = Debug|x64 18 | {617DB37E-D385-450F-9287-21FCF840942A}.Debug|x86.ActiveCfg = Debug|Win32 19 | {617DB37E-D385-450F-9287-21FCF840942A}.Debug|x86.Build.0 = Debug|Win32 20 | {617DB37E-D385-450F-9287-21FCF840942A}.Release|x64.ActiveCfg = Release|x64 21 | {617DB37E-D385-450F-9287-21FCF840942A}.Release|x64.Build.0 = Release|x64 22 | {617DB37E-D385-450F-9287-21FCF840942A}.Release|x86.ActiveCfg = Release|Win32 23 | {617DB37E-D385-450F-9287-21FCF840942A}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {1184C054-D24E-44B9-9DB1-112DB2058CE4} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter02/Section_2.3/TwoSum/TwoSum.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter02/Section_2.3/TwoSum/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "MergeSort.h" 3 | 4 | using namespace std; 5 | 6 | bool TwoSum(int data[], int n, int sum) 7 | { 8 | if(data != NULL || n > 1) 9 | { 10 | merge_sort(data, n); 11 | 12 | int i = 0; 13 | int j = n-1; 14 | 15 | while(i < j) 16 | { 17 | if(data[i] + data[j] < sum) 18 | { 19 | i++; 20 | } 21 | else if(data[i] + data[j] > sum) 22 | { 23 | j--; 24 | } 25 | else 26 | { 27 | cout << data[i] << " + " << data[j] << " = " << sum << "\n"; 28 | return true; 29 | } 30 | } 31 | } 32 | 33 | cout << "No 2 elements whose sum is equle to " << sum << "\n"; 34 | return false; 35 | } 36 | 37 | int main() 38 | { 39 | int a1[] = {5, 4, 2, 1, 5, 7, 4, 5}; 40 | TwoSum(a1, sizeof(a1)/sizeof(int), 10); 41 | 42 | int a2[] = {2, 1}; 43 | TwoSum(a2, sizeof(a2)/sizeof(int), 3); 44 | } 45 | -------------------------------------------------------------------------------- /Chapter04/Section_4.1/Exercise_4.1-5/MaxSubarray/.vs/MaxSubarray/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter04/Section_4.1/Exercise_4.1-5/MaxSubarray/.vs/MaxSubarray/v16/.suo -------------------------------------------------------------------------------- /Chapter04/Section_4.1/Exercise_4.1-5/MaxSubarray/MaxSubArray.h: -------------------------------------------------------------------------------- 1 | #ifndef _MAX_SUB_ARRAY_H_ 2 | #define _MAX_SUB_ARRAY_H_ 3 | 4 | template 5 | bool FindMaxSubarray(T data[], int n, int &maxLow, int &maxHigh, T &maxSum) 6 | { 7 | if (data == NULL || n <= 0) 8 | return false; 9 | 10 | T curSum = data[0]; 11 | T curLow = 0; 12 | 13 | maxSum = data[0]; 14 | maxLow = 0; 15 | maxHigh = 0; 16 | 17 | for (int i = 1; i < n; ++i) 18 | { 19 | if (curSum > 0) 20 | { 21 | curSum += data[i]; 22 | } 23 | else 24 | { 25 | curSum = data[i]; 26 | curLow = i; 27 | } 28 | 29 | if (curSum > maxSum) 30 | { 31 | maxSum = curSum; 32 | maxLow = curLow; 33 | maxHigh = i; 34 | } 35 | } 36 | 37 | return true; 38 | } 39 | 40 | #endif // _MAX_SUB_ARRAY_H_ 41 | -------------------------------------------------------------------------------- /Chapter04/Section_4.1/Exercise_4.1-5/MaxSubarray/MaxSubarray.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MaxSubarray", "MaxSubarray.vcxproj", "{80D00E62-3A30-4B0B-A019-2EEF04A06F74}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {80D00E62-3A30-4B0B-A019-2EEF04A06F74}.Debug|x64.ActiveCfg = Debug|x64 17 | {80D00E62-3A30-4B0B-A019-2EEF04A06F74}.Debug|x64.Build.0 = Debug|x64 18 | {80D00E62-3A30-4B0B-A019-2EEF04A06F74}.Debug|x86.ActiveCfg = Debug|Win32 19 | {80D00E62-3A30-4B0B-A019-2EEF04A06F74}.Debug|x86.Build.0 = Debug|Win32 20 | {80D00E62-3A30-4B0B-A019-2EEF04A06F74}.Release|x64.ActiveCfg = Release|x64 21 | {80D00E62-3A30-4B0B-A019-2EEF04A06F74}.Release|x64.Build.0 = Release|x64 22 | {80D00E62-3A30-4B0B-A019-2EEF04A06F74}.Release|x86.ActiveCfg = Release|Win32 23 | {80D00E62-3A30-4B0B-A019-2EEF04A06F74}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {051153CE-E75C-4CD9-9674-D56BC8B053EE} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter04/Section_4.1/Exercise_4.1-5/MaxSubarray/MaxSubarray.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter04/Section_4.1/Exercise_4.1-5/MaxSubarray/MaxSubarray.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter04/Section_4.1/Exercise_4.1-5/MaxSubarray/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "MaxSubArray.h" 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int a1[] ={ 13, -3, -25, 20, -3, -16, -23, 18, 20, -7, 12, -5, -22, 15, -4, 7 }; 9 | int maxLow1, maxHigh1, maxSum1; 10 | FindMaxSubarray(a1, sizeof(a1)/sizeof(int), maxLow1, maxHigh1, maxSum1); 11 | cout << "maxLow1 = " << maxLow1 << "\tmaxHigh1 = " << maxHigh1 << "\tmaxSum1 = " << maxSum1 << "\n"; 12 | 13 | int a2[] ={ 1, -4, 3, -4 }; 14 | int maxLow2, maxHigh2, maxSum2; 15 | FindMaxSubarray(a2, sizeof(a2)/sizeof(int), maxLow2, maxHigh2, maxSum2); 16 | cout << "maxLow2 = " << maxLow2 << "\tmaxHigh2 = " << maxHigh2 << "\tmaxSum2 = " << maxSum2 << "\n"; 17 | 18 | int a3[] ={ -2, -3, -1 }; 19 | int maxLow3, maxHigh3, maxSum3; 20 | FindMaxSubarray(a3, sizeof(a3)/sizeof(int), maxLow3, maxHigh3, maxSum3); 21 | cout << "maxLow3 = " << maxLow3 << "\tmaxHigh3 = " << maxHigh3 << "\tmaxSum3 = " << maxSum3 << "\n"; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Chapter04/Section_4.1/MaxSubArray/.vs/MaxSubArray/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter04/Section_4.1/MaxSubArray/.vs/MaxSubArray/v16/.suo -------------------------------------------------------------------------------- /Chapter04/Section_4.1/MaxSubArray/MaxSubArray.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MaxSubArray", "MaxSubArray.vcxproj", "{1103F321-1177-4ED6-89C7-489382077F9A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {1103F321-1177-4ED6-89C7-489382077F9A}.Debug|x64.ActiveCfg = Debug|x64 17 | {1103F321-1177-4ED6-89C7-489382077F9A}.Debug|x64.Build.0 = Debug|x64 18 | {1103F321-1177-4ED6-89C7-489382077F9A}.Debug|x86.ActiveCfg = Debug|Win32 19 | {1103F321-1177-4ED6-89C7-489382077F9A}.Debug|x86.Build.0 = Debug|Win32 20 | {1103F321-1177-4ED6-89C7-489382077F9A}.Release|x64.ActiveCfg = Release|x64 21 | {1103F321-1177-4ED6-89C7-489382077F9A}.Release|x64.Build.0 = Release|x64 22 | {1103F321-1177-4ED6-89C7-489382077F9A}.Release|x86.ActiveCfg = Release|Win32 23 | {1103F321-1177-4ED6-89C7-489382077F9A}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {FC3B29E7-9316-4ECE-A578-8A737925DCAE} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter04/Section_4.1/MaxSubArray/MaxSubArray.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter04/Section_4.1/MaxSubArray/MaxSubArray.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter04/Section_4.1/MaxSubArray/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "MaxSubArray.h" 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int a1[] = {13, -3, -25, 20, -3, -16, -23, 18, 20, -7, 12, -5, -22, 15, -4, 7}; 9 | int maxLow1, maxHigh1, maxSum1; 10 | FindMaxSubarray(a1, sizeof(a1)/sizeof(int), maxLow1, maxHigh1, maxSum1); 11 | cout << "maxLow1 = " << maxLow1 << "\tmaxHigh1 = " << maxHigh1 << "\tmaxSum1 = " << maxSum1 << "\n"; 12 | 13 | int a2[] ={ 1, -4, 3, -4 }; 14 | int maxLow2, maxHigh2, maxSum2; 15 | FindMaxSubarray(a2, sizeof(a2)/sizeof(int), maxLow2, maxHigh2, maxSum2); 16 | cout << "maxLow2 = " << maxLow2 << "\tmaxHigh2 = " << maxHigh2 << "\tmaxSum2 = " << maxSum2 << "\n"; 17 | 18 | int a3[] ={ 1, 2, 7, 1 }; 19 | int maxLow3, maxHigh3, maxSum3; 20 | FindMaxSubarray(a3, sizeof(a3)/sizeof(int), maxLow3, maxHigh3, maxSum3); 21 | cout << "maxLow3 = " << maxLow3 << "\tmaxHigh3 = " << maxHigh3 << "\tmaxSum3 = " << maxSum3 << "\n"; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Chapter04/Section_4.2/StrassenSquareMatrixMultiply/.vs/StrassenSquareMatrixMultiply/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter04/Section_4.2/StrassenSquareMatrixMultiply/.vs/StrassenSquareMatrixMultiply/v16/.suo -------------------------------------------------------------------------------- /Chapter04/Section_4.2/StrassenSquareMatrixMultiply/StrassenSquareMatrixMultiply.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StrassenSquareMatrixMultiply", "StrassenSquareMatrixMultiply.vcxproj", "{CB10BFD8-F7EF-4BA5-92E8-3A5027287D21}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {CB10BFD8-F7EF-4BA5-92E8-3A5027287D21}.Debug|x64.ActiveCfg = Debug|x64 17 | {CB10BFD8-F7EF-4BA5-92E8-3A5027287D21}.Debug|x64.Build.0 = Debug|x64 18 | {CB10BFD8-F7EF-4BA5-92E8-3A5027287D21}.Debug|x86.ActiveCfg = Debug|Win32 19 | {CB10BFD8-F7EF-4BA5-92E8-3A5027287D21}.Debug|x86.Build.0 = Debug|Win32 20 | {CB10BFD8-F7EF-4BA5-92E8-3A5027287D21}.Release|x64.ActiveCfg = Release|x64 21 | {CB10BFD8-F7EF-4BA5-92E8-3A5027287D21}.Release|x64.Build.0 = Release|x64 22 | {CB10BFD8-F7EF-4BA5-92E8-3A5027287D21}.Release|x86.ActiveCfg = Release|Win32 23 | {CB10BFD8-F7EF-4BA5-92E8-3A5027287D21}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {2B476F99-1D45-42CE-BEB8-2A24B9B9DF1D} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter04/Section_4.2/StrassenSquareMatrixMultiply/StrassenSquareMatrixMultiply.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter04/Section_4.2/StrassenSquareMatrixMultiply/StrassenSquareMatrixMultiply.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter04/Section_4.2/StrassenSquareMatrixMultiply/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "StrassenSquareMatrixMultiply.h" 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int a1[4] = { 1, 3, 7, 5 }; 9 | int b1[4] = { 6, 8, 4, 2 }; 10 | int c1[4] = { 0 }; 11 | StrassenSquareMatrixMultiply(a1, b1, 2, c1); 12 | cout << "c1 = \n"; 13 | for (int i = 0; i < 4; ++i) 14 | { 15 | cout << c1[i] << "\t"; 16 | if (i % 2 == 1) 17 | cout << "\n"; 18 | } 19 | cout << "\n"; 20 | 21 | int a2[9] ={ 3, -1, 2, 1, 5, 7, 2, 4, 5 }; 22 | int b2[9] ={ 7, 5, -2, 5, 1, 9, 4, 2, 1 }; 23 | int c2[9] ={ 0 }; 24 | StrassenSquareMatrixMultiply(a2, b2, 3, c2); 25 | cout << "c2 = \n"; 26 | for (int i = 0; i < 9; ++i) 27 | { 28 | cout << c2[i] << "\t"; 29 | if (i % 3 == 2) 30 | cout << "\n"; 31 | } 32 | cout << "\n"; 33 | 34 | double a3[36] ={ 0.5377, -0.4336, 0.7254, 1.4090, 0.4889, 0.8884, 35 | 1.8339, 0.3426, -0.0631, 1.4172, 1.0347, -1.1471, 36 | -2.2588, 3.5784, 0.7147, 0.6715, 0.7269, -1.0689, 37 | 0.8622, 2.7694, -0.2050, -1.2075, -0.3034, -0.8095, 38 | 0.3188, -1.3499, -0.1241, 0.7172, 0.2939, -2.9443, 39 | -1.3077, 3.0349, 1.4897, 1.6302, -0.7873, 1.4384 }; 40 | double b3[36] ={ 0.3252, 0.3192, 1.0933, -0.0068, -1.0891, -1.4916, 41 | -0.7549, 0.3129, 1.1093, 1.5326, 0.0326, -0.7423, 42 | 1.3703, -0.8649, -0.8637, -0.7697, 0.5525, -1.0616, 43 | -1.7115, -0.0301, 0.0774, 0.3714, 1.1006, 2.3505, 44 | -0.1022, -0.1649, -1.2141, -0.2256, 1.5442, -0.6156, 45 | -0.2414, 0.6277, -1.1135, 1.1174, 0.0859, 0.7481 }; 46 | double c3[36] ={ 0 }; 47 | StrassenSquareMatrixMultiply(a3, b3, 6, c3); 48 | cout << "c3 = \n"; 49 | for (int i = 0; i < 36; ++i) 50 | { 51 | cout << c3[i] << "\t"; 52 | if (i % 6 == 5) 53 | cout << "\n"; 54 | } 55 | cout << "\n"; 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /Chapter06/HeapSort/.vs/HeapSort/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/HeapSort/.vs/HeapSort/v15/.suo -------------------------------------------------------------------------------- /Chapter06/HeapSort/HeapSort.h: -------------------------------------------------------------------------------- 1 | #ifndef _HEAP_SORT_H_ 2 | #define _HEAP_SORT_H_ 3 | 4 | inline int LEFT(int i) 5 | { 6 | return (i<<1) + 1; 7 | } 8 | 9 | template 10 | void MaxHeapify(T data[], int n, int i) 11 | { 12 | T tmp = data[i]; 13 | int left = LEFT(i); 14 | 15 | while (left < n) 16 | { 17 | int right = left + 1; 18 | int maxChild = (right < n && data[left] < data[right]) ? right : left; 19 | 20 | if (tmp < data[maxChild]) 21 | { 22 | data[i] = data[maxChild]; 23 | i = maxChild; 24 | left = LEFT(i); 25 | } 26 | else 27 | break; 28 | } 29 | 30 | data[i] = tmp; 31 | } 32 | 33 | template 34 | inline void exchange(T& x, T& y) 35 | { 36 | T t = x; 37 | x = y; 38 | y = t; 39 | } 40 | 41 | template 42 | void HeapSort(T data[], int n) 43 | { 44 | if (data != NULL) 45 | { 46 | for (int i = n/2-1; i >= 0; --i) 47 | MaxHeapify(data, n, i); 48 | 49 | for (int i = n-1; i > 0; --i) 50 | { 51 | exchange(data[0], data[i]); 52 | MaxHeapify(data, i, 0); 53 | } 54 | } 55 | } 56 | 57 | #endif // #ifndef _HEAP_SORT_H_ 58 | 59 | -------------------------------------------------------------------------------- /Chapter06/HeapSort/HeapSort.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HeapSort", "HeapSort.vcxproj", "{FFAA92D0-7BED-475C-AB69-DA1E5FC3D183}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {FFAA92D0-7BED-475C-AB69-DA1E5FC3D183}.Debug|x64.ActiveCfg = Debug|x64 17 | {FFAA92D0-7BED-475C-AB69-DA1E5FC3D183}.Debug|x64.Build.0 = Debug|x64 18 | {FFAA92D0-7BED-475C-AB69-DA1E5FC3D183}.Debug|x86.ActiveCfg = Debug|Win32 19 | {FFAA92D0-7BED-475C-AB69-DA1E5FC3D183}.Debug|x86.Build.0 = Debug|Win32 20 | {FFAA92D0-7BED-475C-AB69-DA1E5FC3D183}.Release|x64.ActiveCfg = Release|x64 21 | {FFAA92D0-7BED-475C-AB69-DA1E5FC3D183}.Release|x64.Build.0 = Release|x64 22 | {FFAA92D0-7BED-475C-AB69-DA1E5FC3D183}.Release|x86.ActiveCfg = Release|Win32 23 | {FFAA92D0-7BED-475C-AB69-DA1E5FC3D183}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {7C20A554-1735-4A84-BCD3-AC2812D4DF14} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter06/HeapSort/HeapSort.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter06/HeapSort/HeapSort.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter06/HeapSort/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "HeapSort.h" 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int a[] = { 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 }; 9 | 10 | HeapSort(a, sizeof(a)/sizeof(int)); 11 | 12 | for (int i = 0; i < sizeof(a)/sizeof(int); ++i) 13 | cout << a[i] << " "; 14 | cout << "\n"; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/.vs/DMaxHeapDemo/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-2/DMaxHeapDemo/.vs/DMaxHeapDemo/v15/.suo -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/DHeapView.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-2/DMaxHeapDemo/DHeapView.cpp -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/DHeapView.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-2/DMaxHeapDemo/DHeapView.h -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/DMaxHeapDemo.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-2/DMaxHeapDemo/DMaxHeapDemo.aps -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/DMaxHeapDemo.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-2/DMaxHeapDemo/DMaxHeapDemo.cpp -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/DMaxHeapDemo.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-2/DMaxHeapDemo/DMaxHeapDemo.h -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/DMaxHeapDemo.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-2/DMaxHeapDemo/DMaxHeapDemo.rc -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/DMaxHeapDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DMaxHeapDemo", "DMaxHeapDemo.vcxproj", "{74DD293D-DAFC-40B6-BB9E-BE97AF95C0CF}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {74DD293D-DAFC-40B6-BB9E-BE97AF95C0CF}.Debug|x64.ActiveCfg = Debug|x64 17 | {74DD293D-DAFC-40B6-BB9E-BE97AF95C0CF}.Debug|x64.Build.0 = Debug|x64 18 | {74DD293D-DAFC-40B6-BB9E-BE97AF95C0CF}.Debug|x86.ActiveCfg = Debug|Win32 19 | {74DD293D-DAFC-40B6-BB9E-BE97AF95C0CF}.Debug|x86.Build.0 = Debug|Win32 20 | {74DD293D-DAFC-40B6-BB9E-BE97AF95C0CF}.Release|x64.ActiveCfg = Release|x64 21 | {74DD293D-DAFC-40B6-BB9E-BE97AF95C0CF}.Release|x64.Build.0 = Release|x64 22 | {74DD293D-DAFC-40B6-BB9E-BE97AF95C0CF}.Release|x86.ActiveCfg = Release|Win32 23 | {74DD293D-DAFC-40B6-BB9E-BE97AF95C0CF}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {8E329A83-2802-4120-952D-B9D16B8427D3} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/DMaxHeapDemo.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | DMaxHeapDemo.rc 5 | 6 | -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/DMaxHeapDemoDlg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-2/DMaxHeapDemo/DMaxHeapDemoDlg.cpp -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/DMaxHeapDemoDlg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-2/DMaxHeapDemo/DMaxHeapDemoDlg.h -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/res/DMaxHeapDemo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-2/DMaxHeapDemo/res/DMaxHeapDemo.ico -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/res/DMaxHeapDemo.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-2/DMaxHeapDemo/res/DMaxHeapDemo.rc2 -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-2/DMaxHeapDemo/resource.h -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-2/DMaxHeapDemo/stdafx.cpp -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-2/DMaxHeapDemo/stdafx.h -------------------------------------------------------------------------------- /Chapter06/Problem_6-2/DMaxHeapDemo/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-2/DMaxHeapDemo/targetver.h -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/.vs/YoungMatrix/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-3/YoungMatrix/.vs/YoungMatrix/v15/.suo -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/YoungMatrix.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-3/YoungMatrix/YoungMatrix.aps -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/YoungMatrix.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-3/YoungMatrix/YoungMatrix.cpp -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/YoungMatrix.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-3/YoungMatrix/YoungMatrix.h -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/YoungMatrix.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-3/YoungMatrix/YoungMatrix.rc -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/YoungMatrix.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "YoungMatrix", "YoungMatrix.vcxproj", "{05A2CBED-6C04-43E6-A017-8EC6E2B982D6}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {05A2CBED-6C04-43E6-A017-8EC6E2B982D6}.Debug|x64.ActiveCfg = Debug|x64 17 | {05A2CBED-6C04-43E6-A017-8EC6E2B982D6}.Debug|x64.Build.0 = Debug|x64 18 | {05A2CBED-6C04-43E6-A017-8EC6E2B982D6}.Debug|x86.ActiveCfg = Debug|Win32 19 | {05A2CBED-6C04-43E6-A017-8EC6E2B982D6}.Debug|x86.Build.0 = Debug|Win32 20 | {05A2CBED-6C04-43E6-A017-8EC6E2B982D6}.Release|x64.ActiveCfg = Release|x64 21 | {05A2CBED-6C04-43E6-A017-8EC6E2B982D6}.Release|x64.Build.0 = Release|x64 22 | {05A2CBED-6C04-43E6-A017-8EC6E2B982D6}.Release|x86.ActiveCfg = Release|Win32 23 | {05A2CBED-6C04-43E6-A017-8EC6E2B982D6}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {F5CC31B6-4B75-4113-81B3-F525C9C2C82B} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/YoungMatrix.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | YoungMatrix.rc 5 | 6 | -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/YoungMatrixDlg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-3/YoungMatrix/YoungMatrixDlg.cpp -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/YoungMatrixDlg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-3/YoungMatrix/YoungMatrixDlg.h -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/YoungMatrixView.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-3/YoungMatrix/YoungMatrixView.cpp -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/YoungMatrixView.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-3/YoungMatrix/YoungMatrixView.h -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/res/YoungMatrix.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-3/YoungMatrix/res/YoungMatrix.ico -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/res/YoungMatrix.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-3/YoungMatrix/res/YoungMatrix.rc2 -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-3/YoungMatrix/resource.h -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-3/YoungMatrix/stdafx.cpp -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-3/YoungMatrix/stdafx.h -------------------------------------------------------------------------------- /Chapter06/Problem_6-3/YoungMatrix/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Problem_6-3/YoungMatrix/targetver.h -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/.vs/MaxPriorityQueueDemo/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Section_6.5/MaxPriorityQueueDemo/.vs/MaxPriorityQueueDemo/v15/.suo -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/BinaryHeapView.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Section_6.5/MaxPriorityQueueDemo/BinaryHeapView.cpp -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/BinaryHeapView.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Section_6.5/MaxPriorityQueueDemo/BinaryHeapView.h -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/MaxPriorityQueueDemo.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Section_6.5/MaxPriorityQueueDemo/MaxPriorityQueueDemo.aps -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/MaxPriorityQueueDemo.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Section_6.5/MaxPriorityQueueDemo/MaxPriorityQueueDemo.cpp -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/MaxPriorityQueueDemo.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Section_6.5/MaxPriorityQueueDemo/MaxPriorityQueueDemo.h -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/MaxPriorityQueueDemo.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Section_6.5/MaxPriorityQueueDemo/MaxPriorityQueueDemo.rc -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/MaxPriorityQueueDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MaxPriorityQueueDemo", "MaxPriorityQueueDemo.vcxproj", "{F564E2A4-3446-4252-A5DB-B4E6D6AC65B4}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {F564E2A4-3446-4252-A5DB-B4E6D6AC65B4}.Debug|x64.ActiveCfg = Debug|x64 17 | {F564E2A4-3446-4252-A5DB-B4E6D6AC65B4}.Debug|x64.Build.0 = Debug|x64 18 | {F564E2A4-3446-4252-A5DB-B4E6D6AC65B4}.Debug|x86.ActiveCfg = Debug|Win32 19 | {F564E2A4-3446-4252-A5DB-B4E6D6AC65B4}.Debug|x86.Build.0 = Debug|Win32 20 | {F564E2A4-3446-4252-A5DB-B4E6D6AC65B4}.Release|x64.ActiveCfg = Release|x64 21 | {F564E2A4-3446-4252-A5DB-B4E6D6AC65B4}.Release|x64.Build.0 = Release|x64 22 | {F564E2A4-3446-4252-A5DB-B4E6D6AC65B4}.Release|x86.ActiveCfg = Release|Win32 23 | {F564E2A4-3446-4252-A5DB-B4E6D6AC65B4}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {D6759D26-94C8-475B-81AD-908650AB6E23} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/MaxPriorityQueueDemo.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | MaxPriorityQueueDemo.rc 5 | 6 | -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/MaxPriorityQueueDemoDlg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Section_6.5/MaxPriorityQueueDemo/MaxPriorityQueueDemoDlg.cpp -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/MaxPriorityQueueDemoDlg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Section_6.5/MaxPriorityQueueDemo/MaxPriorityQueueDemoDlg.h -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/res/MaxPriorityQueueDemo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Section_6.5/MaxPriorityQueueDemo/res/MaxPriorityQueueDemo.ico -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/res/MaxPriorityQueueDemo.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Section_6.5/MaxPriorityQueueDemo/res/MaxPriorityQueueDemo.rc2 -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Section_6.5/MaxPriorityQueueDemo/resource.h -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Section_6.5/MaxPriorityQueueDemo/stdafx.cpp -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Section_6.5/MaxPriorityQueueDemo/stdafx.h -------------------------------------------------------------------------------- /Chapter06/Section_6.5/MaxPriorityQueueDemo/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter06/Section_6.5/MaxPriorityQueueDemo/targetver.h -------------------------------------------------------------------------------- /Chapter07/Problem_7-1/HoareQuickSort/.vs/HoareQuickSort/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter07/Problem_7-1/HoareQuickSort/.vs/HoareQuickSort/v15/.suo -------------------------------------------------------------------------------- /Chapter07/Problem_7-1/HoareQuickSort/HoareQuickSort.h: -------------------------------------------------------------------------------- 1 | #ifndef _HOARE_QUICK_SORT_H_ 2 | #define _HOARE_QUICK_SORT_H_ 3 | 4 | template 5 | inline void swap(T &x, T &y) 6 | { 7 | T tmp = x; 8 | x = y; 9 | y = tmp; 10 | } 11 | 12 | template 13 | int hoare_partition(T data[], int left, int right) 14 | { 15 | T pivot = data[left]; 16 | 17 | while (true) 18 | { 19 | while (data[left] < pivot) left++; 20 | while (pivot < data[right]) right--; 21 | if (left < right) swap(data[left++], data[right--]); 22 | else return right; 23 | } 24 | } 25 | 26 | template 27 | void hoare_quick_sort(T data[], int left, int right) 28 | { 29 | if (left < right) 30 | { 31 | int mid = hoare_partition(data, left, right); 32 | hoare_quick_sort(data, left, mid); 33 | hoare_quick_sort(data, mid+1, right); 34 | } 35 | } 36 | 37 | template 38 | void hoare_quick_sort(T data[], int n) 39 | { 40 | if (data != NULL) 41 | hoare_quick_sort(data, 0, n-1); 42 | } 43 | 44 | #endif // #ifndef _HOARE_QUICK_SORT_H_ 45 | -------------------------------------------------------------------------------- /Chapter07/Problem_7-1/HoareQuickSort/HoareQuickSort.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HoareQuickSort", "HoareQuickSort.vcxproj", "{1624090F-730F-4733-93EC-AF9056FF25D9}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {1624090F-730F-4733-93EC-AF9056FF25D9}.Debug|x64.ActiveCfg = Debug|x64 17 | {1624090F-730F-4733-93EC-AF9056FF25D9}.Debug|x64.Build.0 = Debug|x64 18 | {1624090F-730F-4733-93EC-AF9056FF25D9}.Debug|x86.ActiveCfg = Debug|Win32 19 | {1624090F-730F-4733-93EC-AF9056FF25D9}.Debug|x86.Build.0 = Debug|Win32 20 | {1624090F-730F-4733-93EC-AF9056FF25D9}.Release|x64.ActiveCfg = Release|x64 21 | {1624090F-730F-4733-93EC-AF9056FF25D9}.Release|x64.Build.0 = Release|x64 22 | {1624090F-730F-4733-93EC-AF9056FF25D9}.Release|x86.ActiveCfg = Release|Win32 23 | {1624090F-730F-4733-93EC-AF9056FF25D9}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {41543A47-8D2F-4EF3-BD7D-F9A1EAB7AC91} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter07/Problem_7-1/HoareQuickSort/HoareQuickSort.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter07/Problem_7-1/HoareQuickSort/HoareQuickSort.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter07/Problem_7-1/HoareQuickSort/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "HoareQuickSort.h" 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int a[] = { 2, 8, 7, 1, 3, 5, 6, 4 }; 9 | int d[] = { 13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11 }; 10 | 11 | hoare_quick_sort(a, sizeof(a)/sizeof(int)); 12 | for (int i = 0; i < sizeof(a)/sizeof(int); ++i) 13 | cout << a[i] << " "; 14 | cout << "\n"; 15 | 16 | hoare_quick_sort(d, sizeof(d)/sizeof(int)); 17 | for (int i = 0; i < sizeof(d)/sizeof(int); ++i) 18 | cout << d[i] << " "; 19 | cout << "\n"; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Chapter07/Problem_7-2/SameElemQuickSort/.vs/SameElemQuickSort/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter07/Problem_7-2/SameElemQuickSort/.vs/SameElemQuickSort/v15/.suo -------------------------------------------------------------------------------- /Chapter07/Problem_7-2/SameElemQuickSort/SameElemQuickSort.h: -------------------------------------------------------------------------------- 1 | #ifndef _SAME_ELEM_QUICK_SORT_H_ 2 | #define _SAME_ELEM_QUICK_SORT_H_ 3 | 4 | struct SplitPosType 5 | { 6 | SplitPosType(int p1, int p2) : pos1(p1), pos2(p2) {} 7 | 8 | int pos1; 9 | int pos2; 10 | }; 11 | 12 | template 13 | inline void swap(T &x, T &y) 14 | { 15 | if(&x != &y) 16 | { 17 | T tmp = x; 18 | x = y; 19 | y = tmp; 20 | } 21 | } 22 | 23 | template 24 | SplitPosType same_elem_partition(T data[], int left, int right) 25 | { 26 | int q = left - 1; 27 | int t = left - 1; 28 | 29 | for(int k = left; k < right; ++k) 30 | { 31 | if(data[k] < data[right]) 32 | { 33 | q++; 34 | t++; 35 | swap(data[q], data[k]); 36 | 37 | if(q != t) 38 | swap(data[t], data[k]); 39 | } 40 | else if(data[k] == data[right]) 41 | { 42 | t++; 43 | swap(data[t], data[k]); 44 | } 45 | } 46 | 47 | q++; 48 | t++; 49 | swap(data[t], data[right]); 50 | 51 | return SplitPosType(q, t); 52 | } 53 | 54 | template 55 | void same_elem_quick_sort(T data[], int left, int right) 56 | { 57 | if (left < right) 58 | { 59 | SplitPosType splitPos = same_elem_partition(data, left, right); 60 | same_elem_quick_sort(data, left, splitPos.pos1-1); 61 | same_elem_quick_sort(data, splitPos.pos2+1, right); 62 | } 63 | } 64 | 65 | template 66 | void same_elem_quick_sort(T data[], int n) 67 | { 68 | if (data != NULL) 69 | same_elem_quick_sort(data, 0, n-1); 70 | } 71 | 72 | #endif // #ifndef _SAME_ELEM_QUICK_SORT_H_ 73 | -------------------------------------------------------------------------------- /Chapter07/Problem_7-2/SameElemQuickSort/SameElemQuickSort.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SameElemQuickSort", "SameElemQuickSort.vcxproj", "{FE05E683-7A61-4D83-A2FB-3971F00668A2}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {FE05E683-7A61-4D83-A2FB-3971F00668A2}.Debug|x64.ActiveCfg = Debug|x64 17 | {FE05E683-7A61-4D83-A2FB-3971F00668A2}.Debug|x64.Build.0 = Debug|x64 18 | {FE05E683-7A61-4D83-A2FB-3971F00668A2}.Debug|x86.ActiveCfg = Debug|Win32 19 | {FE05E683-7A61-4D83-A2FB-3971F00668A2}.Debug|x86.Build.0 = Debug|Win32 20 | {FE05E683-7A61-4D83-A2FB-3971F00668A2}.Release|x64.ActiveCfg = Release|x64 21 | {FE05E683-7A61-4D83-A2FB-3971F00668A2}.Release|x64.Build.0 = Release|x64 22 | {FE05E683-7A61-4D83-A2FB-3971F00668A2}.Release|x86.ActiveCfg = Release|Win32 23 | {FE05E683-7A61-4D83-A2FB-3971F00668A2}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {3554E358-E89E-4A6D-8124-D132C647DD35} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter07/Problem_7-2/SameElemQuickSort/SameElemQuickSort.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter07/Problem_7-2/SameElemQuickSort/SameElemQuickSort.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter07/Problem_7-2/SameElemQuickSort/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SameElemQuickSort.h" 3 | 4 | using namespace std; 5 | 6 | template 7 | void PrintArray(T data[], int n) 8 | { 9 | if(data != NULL) 10 | for(int i = 0; i < n; ++i) 11 | cout << data[i] << "\t"; 12 | } 13 | 14 | int main() 15 | { 16 | int a1[] = { 1, 2 }; 17 | same_elem_quick_sort(a1, sizeof(a1)/sizeof(int)); 18 | PrintArray(a1, sizeof(a1)/sizeof(int)); 19 | cout << "\n\n"; 20 | 21 | int a2[] = { 2, 1 }; 22 | same_elem_quick_sort(a2, sizeof(a2)/sizeof(int)); 23 | PrintArray(a2, sizeof(a2)/sizeof(int)); 24 | cout << "\n\n"; 25 | 26 | int a3[] = { 2, 2, 2, 2 }; 27 | same_elem_quick_sort(a3, sizeof(a3)/sizeof(int)); 28 | PrintArray(a3, sizeof(a3)/sizeof(int)); 29 | cout << "\n\n"; 30 | 31 | int a4[] = { 6, 4, 7, 9, 6, 7, 10, 6 }; 32 | same_elem_quick_sort(a4, sizeof(a4)/sizeof(int)); 33 | PrintArray(a4, sizeof(a4)/sizeof(int)); 34 | cout << "\n\n"; 35 | 36 | int a5[] = { 3, 7, 4, 5, 7 }; 37 | same_elem_quick_sort(a5, sizeof(a5)/sizeof(int)); 38 | PrintArray(a5, sizeof(a5)/sizeof(int)); 39 | cout << "\n\n"; 40 | 41 | int a6[] = { 2, 6, 4, 3, 5 }; 42 | same_elem_quick_sort(a6, sizeof(a6)/sizeof(int)); 43 | PrintArray(a6, sizeof(a6)/sizeof(int)); 44 | cout << "\n\n"; 45 | 46 | int a7[] = { 1, 2, 3, 4, 5, 6, 7 }; 47 | same_elem_quick_sort(a7, sizeof(a7)/sizeof(int)); 48 | PrintArray(a7, sizeof(a7)/sizeof(int)); 49 | cout << "\n\n"; 50 | 51 | int a8[] = { 7, 6, 5, 4, 3, 2, 1 }; 52 | same_elem_quick_sort(a8, sizeof(a8)/sizeof(int)); 53 | PrintArray(a8, sizeof(a8)/sizeof(int)); 54 | cout << "\n\n"; 55 | 56 | int a9[] = { 2, 3, 6, 3, 4, 3, 5 }; 57 | same_elem_quick_sort(a9, sizeof(a9)/sizeof(int)); 58 | PrintArray(a9, sizeof(a9)/sizeof(int)); 59 | cout << "\n\n"; 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /Chapter07/Problem_7-4/TailRecursiveQuicksort/.vs/TailRecursiveQuicksort/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter07/Problem_7-4/TailRecursiveQuicksort/.vs/TailRecursiveQuicksort/v15/.suo -------------------------------------------------------------------------------- /Chapter07/Problem_7-4/TailRecursiveQuicksort/TailRecursiveQuicksort.h: -------------------------------------------------------------------------------- 1 | #ifndef _TAIL_RECURSIVE_QUICKSORT_H_ 2 | #define _TAIL_RECURSIVE_QUICKSORT_H_ 3 | 4 | template 5 | inline void swap(T &x, T &y) 6 | { 7 | T tmp = x; 8 | x = y; 9 | y = tmp; 10 | } 11 | 12 | template 13 | int partition(T data[], int left, int right) 14 | { 15 | for (int i = left; i < right; ++i) 16 | { 17 | if (data[i] <= data[right]) 18 | { 19 | swap(data[left], data[i]); 20 | left++; 21 | } 22 | } 23 | 24 | swap(data[left], data[right]); 25 | return left; 26 | } 27 | 28 | template 29 | void tail_recursive_quick_sort(T data[], int left, int right) 30 | { 31 | while (left < right) 32 | { 33 | int mid = partition(data, left, right); 34 | 35 | if(mid-left <= right-mid) 36 | { 37 | tail_recursive_quick_sort(data, left, mid-1); 38 | left = mid + 1; 39 | } 40 | else 41 | { 42 | tail_recursive_quick_sort(data, mid+1, right); 43 | right = mid - 1; 44 | } 45 | } 46 | } 47 | 48 | template 49 | void tail_recursive_quick_sort(T data[], int n) 50 | { 51 | if (data != NULL) 52 | tail_recursive_quick_sort(data, 0, n-1); 53 | } 54 | 55 | #endif // #ifndef _TAIL_RECURSIVE_QUICKSORT_H_ 56 | -------------------------------------------------------------------------------- /Chapter07/Problem_7-4/TailRecursiveQuicksort/TailRecursiveQuicksort.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TailRecursiveQuicksort", "TailRecursiveQuicksort.vcxproj", "{54867314-9270-4531-A0DA-CFD9E123389B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {54867314-9270-4531-A0DA-CFD9E123389B}.Debug|x64.ActiveCfg = Debug|x64 17 | {54867314-9270-4531-A0DA-CFD9E123389B}.Debug|x64.Build.0 = Debug|x64 18 | {54867314-9270-4531-A0DA-CFD9E123389B}.Debug|x86.ActiveCfg = Debug|Win32 19 | {54867314-9270-4531-A0DA-CFD9E123389B}.Debug|x86.Build.0 = Debug|Win32 20 | {54867314-9270-4531-A0DA-CFD9E123389B}.Release|x64.ActiveCfg = Release|x64 21 | {54867314-9270-4531-A0DA-CFD9E123389B}.Release|x64.Build.0 = Release|x64 22 | {54867314-9270-4531-A0DA-CFD9E123389B}.Release|x86.ActiveCfg = Release|Win32 23 | {54867314-9270-4531-A0DA-CFD9E123389B}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {2EEE0DF9-2EDF-433B-94B8-462F085BBE04} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter07/Problem_7-4/TailRecursiveQuicksort/TailRecursiveQuicksort.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter07/Problem_7-4/TailRecursiveQuicksort/TailRecursiveQuicksort.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter07/Problem_7-4/TailRecursiveQuicksort/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "TailRecursiveQuicksort.h" 3 | 4 | using namespace std; 5 | 6 | template 7 | void PrintArray(T data[], int n) 8 | { 9 | if(data != NULL) 10 | for(int i = 0; i < n; ++i) 11 | cout << data[i] << "\t"; 12 | } 13 | 14 | int main() 15 | { 16 | int a1[] = { 1, 2 }; 17 | tail_recursive_quick_sort(a1, sizeof(a1)/sizeof(int)); 18 | PrintArray(a1, sizeof(a1)/sizeof(int)); 19 | cout << "\n\n"; 20 | 21 | int a2[] = { 2, 1 }; 22 | tail_recursive_quick_sort(a2, sizeof(a2)/sizeof(int)); 23 | PrintArray(a2, sizeof(a2)/sizeof(int)); 24 | cout << "\n\n"; 25 | 26 | int a3[] = { 2, 2, 2 }; 27 | tail_recursive_quick_sort(a3, sizeof(a3)/sizeof(int)); 28 | PrintArray(a3, sizeof(a3)/sizeof(int)); 29 | cout << "\n\n"; 30 | 31 | int a4[] = { 6, 4, 7, 9, 6, 7, 10, 6 }; 32 | tail_recursive_quick_sort(a4, sizeof(a4)/sizeof(int)); 33 | PrintArray(a4, sizeof(a4)/sizeof(int)); 34 | cout << "\n\n"; 35 | 36 | int a5[] = { 3, 7, 4, 5, 7 }; 37 | tail_recursive_quick_sort(a5, sizeof(a5)/sizeof(int)); 38 | PrintArray(a5, sizeof(a5)/sizeof(int)); 39 | cout << "\n\n"; 40 | 41 | int a6[] = { 2, 6, 4, 3, 5, 2 }; 42 | tail_recursive_quick_sort(a6, sizeof(a6)/sizeof(int)); 43 | PrintArray(a6, sizeof(a6)/sizeof(int)); 44 | cout << "\n\n"; 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Chapter07/Section_7.1/QuickSort/.vs/QuickSort/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter07/Section_7.1/QuickSort/.vs/QuickSort/v15/.suo -------------------------------------------------------------------------------- /Chapter07/Section_7.1/QuickSort/QuickSort.h: -------------------------------------------------------------------------------- 1 | #ifndef _QUICK_SORT_H_ 2 | #define _QUICK_SORT_H_ 3 | 4 | template 5 | inline void swap(T &x, T &y) 6 | { 7 | if(&x != &y) 8 | { 9 | T tmp = x; 10 | x = y; 11 | y = tmp; 12 | } 13 | } 14 | 15 | template 16 | int partition(T data[], int left, int right) 17 | { 18 | for (int i = left; i < right; ++i) 19 | { 20 | if (data[i] <= data[right]) 21 | { 22 | swap(data[left], data[i]); 23 | left++; 24 | } 25 | } 26 | 27 | swap(data[left], data[right]); 28 | return left; 29 | } 30 | 31 | template 32 | void quick_sort(T data[], int left, int right) 33 | { 34 | if (left < right) 35 | { 36 | int mid = partition(data, left, right); 37 | quick_sort(data, left, mid-1); 38 | quick_sort(data, mid+1, right); 39 | } 40 | } 41 | 42 | template 43 | void quick_sort(T data[], int n) 44 | { 45 | if (data != NULL) 46 | quick_sort(data, 0, n-1); 47 | } 48 | 49 | #endif // #ifndef _QUICK_SORT_H_ 50 | -------------------------------------------------------------------------------- /Chapter07/Section_7.1/QuickSort/QuickSort.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QuickSort", "QuickSort.vcxproj", "{DD8D6E8C-610D-4B53-AEBB-4A3DED5FAE8C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {DD8D6E8C-610D-4B53-AEBB-4A3DED5FAE8C}.Debug|x64.ActiveCfg = Debug|x64 17 | {DD8D6E8C-610D-4B53-AEBB-4A3DED5FAE8C}.Debug|x64.Build.0 = Debug|x64 18 | {DD8D6E8C-610D-4B53-AEBB-4A3DED5FAE8C}.Debug|x86.ActiveCfg = Debug|Win32 19 | {DD8D6E8C-610D-4B53-AEBB-4A3DED5FAE8C}.Debug|x86.Build.0 = Debug|Win32 20 | {DD8D6E8C-610D-4B53-AEBB-4A3DED5FAE8C}.Release|x64.ActiveCfg = Release|x64 21 | {DD8D6E8C-610D-4B53-AEBB-4A3DED5FAE8C}.Release|x64.Build.0 = Release|x64 22 | {DD8D6E8C-610D-4B53-AEBB-4A3DED5FAE8C}.Release|x86.ActiveCfg = Release|Win32 23 | {DD8D6E8C-610D-4B53-AEBB-4A3DED5FAE8C}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {FE6C6FE2-6330-4697-B108-E8C5A9389198} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter07/Section_7.1/QuickSort/QuickSort.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter07/Section_7.1/QuickSort/QuickSort.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter07/Section_7.1/QuickSort/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "QuickSort.h" 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int a[] = { 2, 8, 7, 1, 3, 5, 6, 4 }; 9 | int d[] = { 13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11 }; 10 | 11 | quick_sort(a, sizeof(a)/sizeof(int)); 12 | for (int i = 0; i < sizeof(a)/sizeof(int); ++i) 13 | cout << a[i] << " "; 14 | cout << "\n"; 15 | 16 | quick_sort(d, sizeof(d)/sizeof(int)); 17 | for (int i = 0; i < sizeof(d)/sizeof(int); ++i) 18 | cout << d[i] << " "; 19 | cout << "\n"; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Chapter08/Problem_8-2/InPlaceCourtingSort/.vs/InPlaceCourtingSort/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter08/Problem_8-2/InPlaceCourtingSort/.vs/InPlaceCourtingSort/v16/.suo -------------------------------------------------------------------------------- /Chapter08/Problem_8-2/InPlaceCourtingSort/InPlaceCountingSort.h: -------------------------------------------------------------------------------- 1 | #ifndef _COUNTING_SORT_H_ 2 | #define _COUNTING_SORT_H_ 3 | 4 | template 5 | static void exchange(T &x, T &y) 6 | { 7 | T t = x; 8 | x = y; 9 | y = t; 10 | } 11 | 12 | template 13 | void counting_sort_in_place(T src[], int n, int min, int max) 14 | { 15 | int range = max - min + 1; 16 | int *count = new int[range]; 17 | 18 | for (int i = 0; i < range; ++i) 19 | count[i] = 0; 20 | 21 | for (int i = 0; i < n; ++i) 22 | count[src[i]-min]++; 23 | 24 | for (int i = 1; i < range; ++i) 25 | count[i] += count[i-1]; 26 | 27 | for (int i = n-1; i >= 0; --i) { 28 | int p = count[src[i]-min] - 1; 29 | while (p > i) 30 | { 31 | count[src[i]-min]--; 32 | exchange(src[i], src[p]); 33 | p = count[src[i]-min] - 1; 34 | } 35 | } 36 | 37 | delete[] count; 38 | } 39 | 40 | template 41 | void counting_sort_in_place(T data[], int n) 42 | { 43 | if (data == NULL || n <= 1) 44 | return; 45 | 46 | int i; 47 | T min, max; 48 | T *temp = new T[n]; 49 | 50 | min = max = data[0]; 51 | 52 | for (i = 1; i < n-1; i += 2) 53 | { 54 | if (data[i] <= data[i+1]) { 55 | if (data[i] < min) min = data[i]; 56 | if (data[i+1] > max) max = data[i+1]; 57 | } 58 | else { 59 | if (data[i+1] < min) min = data[i+1]; 60 | if (data[i] > max) max = data[i]; 61 | } 62 | } 63 | 64 | if (i < n) { 65 | if (data[i] < min) min = data[i]; 66 | else if (data[i] > max) max = data[i]; 67 | } 68 | 69 | counting_sort_in_place(data, n, min, max); 70 | 71 | delete[] temp; 72 | } 73 | 74 | #endif // #ifndef _COUNTING_SORT_H_ 75 | -------------------------------------------------------------------------------- /Chapter08/Problem_8-2/InPlaceCourtingSort/InPlaceCourtingSort.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29709.97 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "InPlaceCourtingSort", "InPlaceCourtingSort.vcxproj", "{DE1B72B8-873E-4B0E-A1AB-C14EAFBE9DF8}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {DE1B72B8-873E-4B0E-A1AB-C14EAFBE9DF8}.Debug|x64.ActiveCfg = Debug|x64 17 | {DE1B72B8-873E-4B0E-A1AB-C14EAFBE9DF8}.Debug|x64.Build.0 = Debug|x64 18 | {DE1B72B8-873E-4B0E-A1AB-C14EAFBE9DF8}.Debug|x86.ActiveCfg = Debug|Win32 19 | {DE1B72B8-873E-4B0E-A1AB-C14EAFBE9DF8}.Debug|x86.Build.0 = Debug|Win32 20 | {DE1B72B8-873E-4B0E-A1AB-C14EAFBE9DF8}.Release|x64.ActiveCfg = Release|x64 21 | {DE1B72B8-873E-4B0E-A1AB-C14EAFBE9DF8}.Release|x64.Build.0 = Release|x64 22 | {DE1B72B8-873E-4B0E-A1AB-C14EAFBE9DF8}.Release|x86.ActiveCfg = Release|Win32 23 | {DE1B72B8-873E-4B0E-A1AB-C14EAFBE9DF8}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {CB3D4736-AE95-44C6-988C-1CF8087792BF} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter08/Problem_8-2/InPlaceCourtingSort/InPlaceCourtingSort.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter08/Problem_8-2/InPlaceCourtingSort/InPlaceCourtingSort.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter08/Problem_8-2/InPlaceCourtingSort/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "InPlaceCountingSort.h" 3 | 4 | using namespace std; 5 | 6 | void print_array(int data[], int n) 7 | { 8 | for (int i = 0; i < n; ++i) 9 | cout << data[i] << " "; 10 | cout << "\n"; 11 | } 12 | 13 | int main() 14 | { 15 | int array1[] = { 2, 5, 3, -1, 2, 3, -2, 3, -3, -7 }; 16 | counting_sort_in_place(array1, sizeof(array1)/sizeof(int)); 17 | print_array(array1, sizeof(array1)/sizeof(int)); 18 | 19 | int array2[] = { 6, 0, 2, 0, 1, 3, 4, 6, 1, 3, 2 }; 20 | counting_sort_in_place(array2, sizeof(array2)/sizeof(int)); 21 | print_array(array2, sizeof(array2)/sizeof(int)); 22 | 23 | int array3[] = { -1, -1, -1, -1 }; 24 | counting_sort_in_place(array3, sizeof(array3)/sizeof(int)); 25 | print_array(array3, sizeof(array3)/sizeof(int)); 26 | 27 | int array4[] ={ -7, -7 }; 28 | counting_sort_in_place(array4, sizeof(array4)/sizeof(int)); 29 | print_array(array4, sizeof(array4)/sizeof(int)); 30 | 31 | int array5[] ={ 20, -100 }; 32 | counting_sort_in_place(array5, sizeof(array5)/sizeof(int)); 33 | print_array(array5, sizeof(array5)/sizeof(int)); 34 | 35 | int array6[] ={ 20 }; 36 | counting_sort_in_place(array6, sizeof(array6)/sizeof(int)); 37 | print_array(array6, sizeof(array6)/sizeof(int)); 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Chapter08/Problem_8-3/a/RadixSortUnfixedLengthItems/.vs/RadixSortUnfixedLengthItems/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter08/Problem_8-3/a/RadixSortUnfixedLengthItems/.vs/RadixSortUnfixedLengthItems/v16/.suo -------------------------------------------------------------------------------- /Chapter08/Problem_8-3/a/RadixSortUnfixedLengthItems/RadixSortUnfixedLengthItems.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29709.97 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RadixSortUnfixedLengthItems", "RadixSortUnfixedLengthItems.vcxproj", "{0135418C-429A-4652-A175-7CEB2129217D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {0135418C-429A-4652-A175-7CEB2129217D}.Debug|x64.ActiveCfg = Debug|x64 17 | {0135418C-429A-4652-A175-7CEB2129217D}.Debug|x64.Build.0 = Debug|x64 18 | {0135418C-429A-4652-A175-7CEB2129217D}.Debug|x86.ActiveCfg = Debug|Win32 19 | {0135418C-429A-4652-A175-7CEB2129217D}.Debug|x86.Build.0 = Debug|Win32 20 | {0135418C-429A-4652-A175-7CEB2129217D}.Release|x64.ActiveCfg = Release|x64 21 | {0135418C-429A-4652-A175-7CEB2129217D}.Release|x64.Build.0 = Release|x64 22 | {0135418C-429A-4652-A175-7CEB2129217D}.Release|x86.ActiveCfg = Release|Win32 23 | {0135418C-429A-4652-A175-7CEB2129217D}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {1E73CB13-21AD-422A-847D-5B39E56AE661} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter08/Problem_8-3/a/RadixSortUnfixedLengthItems/RadixSortUnfixedLengthItems.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 头文件 20 | 21 | 22 | 23 | 24 | 源文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter08/Problem_8-3/a/RadixSortUnfixedLengthItems/RadixSortUnfixedLengthItems.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter08/Problem_8-3/a/RadixSortUnfixedLengthItems/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "RadixSortUnfixedLengthItems.h" 3 | 4 | using namespace std; 5 | 6 | template 7 | void print_array(T data[], int n) 8 | { 9 | for (int i = 0; i < n; ++i) 10 | cout << "0x" << hex << (unsigned long)data[i] << " "; 11 | cout << "\n"; 12 | } 13 | 14 | int main() 15 | { 16 | int array1[] ={ 0x1111, 0x329, 0x57, 0x657, 0x0, 0x8, 0x43, 0x720, 0x0, 0x355 }; 17 | cout << "source array: "; 18 | print_array(array1, sizeof(array1)/sizeof(int)); 19 | radix_sort_unfixed_length_items(array1, sizeof(array1)/sizeof(int), 16); 20 | cout << "sorted array: "; 21 | print_array(array1, sizeof(array1)/sizeof(int)); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Chapter08/Problem_8-3/b/SortString/.vs/SortString/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter08/Problem_8-3/b/SortString/.vs/SortString/v16/.suo -------------------------------------------------------------------------------- /Chapter08/Problem_8-3/b/SortString/SortString.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SortString.h" 3 | 4 | static void sort_string(const char *data[], const char *temp[], int index[], int count[], int start, int end, int round) 5 | { 6 | if (start >= end) 7 | return; 8 | 9 | for (int i = 0; i < 27; ++i) 10 | count[i] = 0; 11 | 12 | for (int i = start; i <= end; ++i) 13 | { 14 | temp[i] = data[i]; 15 | int t; 16 | 17 | if (temp[i][round] == '\0') t = 0; 18 | else if (temp[i][round] >= 'a' && temp[i][round] <= 'z') t = temp[i][round]-'a'+1; 19 | else t = t = temp[i][round]-'A'+1; 20 | 21 | index[i] = t; 22 | count[t]++; 23 | } 24 | 25 | for (int i = 1; i < 27; ++i) 26 | count[i] += count[i-1]; 27 | 28 | int *countTemp = new int[27]; 29 | 30 | for (int i = 0; i < 27; ++i) 31 | countTemp[i] = count[i]; 32 | 33 | for (int i = end; i >= start; --i) 34 | { 35 | data[count[index[i]] + start - 1] = temp[i]; 36 | count[index[i]]--; 37 | } 38 | 39 | for (int i = 1; i < 27; ++i) 40 | sort_string(data, temp, index, count, start + countTemp[i-1], 41 | start + countTemp[i] - 1, round + 1); 42 | 43 | delete[] countTemp; 44 | } 45 | 46 | bool sort_string(const char *data[], int n) 47 | { 48 | if (data == NULL || n <= 1) 49 | return false; 50 | 51 | const char **temp = new const char*[n]; 52 | int *count = new int[27]; 53 | int *index = new int[n]; 54 | 55 | sort_string(data, temp, index, count, 0, n-1, 0); 56 | 57 | delete[] temp; 58 | delete[] count; 59 | delete[] index; 60 | 61 | return true; 62 | } 63 | -------------------------------------------------------------------------------- /Chapter08/Problem_8-3/b/SortString/SortString.h: -------------------------------------------------------------------------------- 1 | #ifndef _SORT_STRING_H_ 2 | #define _SORT_STRING_H_ 3 | 4 | bool sort_string(const char *data[], int n); 5 | 6 | #endif // #ifndef _SORT_STRING_H_ 7 | -------------------------------------------------------------------------------- /Chapter08/Problem_8-3/b/SortString/SortString.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29709.97 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SortString", "SortString.vcxproj", "{6222F4B7-E349-4F93-ABDB-54B58D72489C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {6222F4B7-E349-4F93-ABDB-54B58D72489C}.Debug|x64.ActiveCfg = Debug|x64 17 | {6222F4B7-E349-4F93-ABDB-54B58D72489C}.Debug|x64.Build.0 = Debug|x64 18 | {6222F4B7-E349-4F93-ABDB-54B58D72489C}.Debug|x86.ActiveCfg = Debug|Win32 19 | {6222F4B7-E349-4F93-ABDB-54B58D72489C}.Debug|x86.Build.0 = Debug|Win32 20 | {6222F4B7-E349-4F93-ABDB-54B58D72489C}.Release|x64.ActiveCfg = Release|x64 21 | {6222F4B7-E349-4F93-ABDB-54B58D72489C}.Release|x64.Build.0 = Release|x64 22 | {6222F4B7-E349-4F93-ABDB-54B58D72489C}.Release|x86.ActiveCfg = Release|Win32 23 | {6222F4B7-E349-4F93-ABDB-54B58D72489C}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {7D4B524F-5954-45AE-AF6C-D9DC1B1E5C09} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter08/Problem_8-3/b/SortString/SortString.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 26 | 27 | 头文件 28 | 29 | 30 | -------------------------------------------------------------------------------- /Chapter08/Problem_8-3/b/SortString/SortString.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter08/Problem_8-3/b/SortString/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SortString.h" 3 | 4 | using namespace std; 5 | 6 | void print_array(const char *data[], int n) 7 | { 8 | for (int i = 0; i < n; ++i) 9 | cout << data[i] << " "; 10 | cout << "\n"; 11 | } 12 | 13 | int main() 14 | { 15 | const char *array1[] ={ "ab", "b", "a" }; 16 | cout << "original array: "; 17 | print_array(array1, sizeof(array1)/sizeof(char*)); 18 | sort_string(array1, sizeof(array1)/sizeof(char*)); 19 | cout << "sorted array: "; 20 | print_array(array1, sizeof(array1)/sizeof(char*)); 21 | 22 | const char *array2[] ={ "fix", "fox", "box", "I", "at", "fit", "bat", "a" }; 23 | cout << "original array: "; 24 | print_array(array2, sizeof(array2)/sizeof(char*)); 25 | sort_string(array2, sizeof(array2)/sizeof(char*)); 26 | cout << "sorted array: "; 27 | print_array(array2, sizeof(array2)/sizeof(char*)); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Chapter08/Section_8.2/CountingSort/.vs/CountingSort/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter08/Section_8.2/CountingSort/.vs/CountingSort/v16/.suo -------------------------------------------------------------------------------- /Chapter08/Section_8.2/CountingSort/CountingSort.h: -------------------------------------------------------------------------------- 1 | #ifndef _COUNTING_SORT_H_ 2 | #define _COUNTING_SORT_H_ 3 | 4 | template 5 | void counting_sort(T src[], T dst[], int n, int min, int max) 6 | { 7 | int range = max - min + 1; 8 | int *count = new int[range]; 9 | 10 | for (int i = 0; i < range; ++i) 11 | count[i] = 0; 12 | 13 | for (int i = 0; i < n; ++i) 14 | count[src[i]-min]++; 15 | 16 | for (int i = 1; i < range; ++i) 17 | count[i] += count[i-1]; 18 | 19 | for (int i = n-1; i >= 0; --i) { 20 | dst[count[src[i]-min]-1] = src[i]; 21 | count[src[i]-min]--; 22 | } 23 | 24 | delete[] count; 25 | } 26 | 27 | template 28 | void counting_sort(T data[], int n) 29 | { 30 | if (data == NULL || n <= 1) 31 | return; 32 | 33 | int i; 34 | T min, max; 35 | T *temp = new T[n]; 36 | 37 | min = max = data[0]; 38 | 39 | for (i = 1; i < n-1; i += 2) 40 | { 41 | if (data[i] <= data[i+1]) { 42 | if (data[i] < min) min = data[i]; 43 | if (data[i+1] > max) max = data[i+1]; 44 | } 45 | else { 46 | if (data[i+1] < min) min = data[i+1]; 47 | if (data[i] > max) max = data[i]; 48 | } 49 | } 50 | 51 | if (i < n) { 52 | if (data[i] < min) min = data[i]; 53 | else if (data[i] > max) max = data[i]; 54 | } 55 | 56 | for (i = 0; i < n; ++i) 57 | temp[i] = data[i]; 58 | 59 | counting_sort(temp, data, n, min, max); 60 | 61 | delete[] temp; 62 | } 63 | 64 | #endif // #ifndef _COUNTING_SORT_H_ 65 | -------------------------------------------------------------------------------- /Chapter08/Section_8.2/CountingSort/CountingSort.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29424.173 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CountingSort", "CountingSort.vcxproj", "{D93780D5-87B8-4E91-A28D-9F4A8FAE657E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {D93780D5-87B8-4E91-A28D-9F4A8FAE657E}.Debug|x64.ActiveCfg = Debug|x64 17 | {D93780D5-87B8-4E91-A28D-9F4A8FAE657E}.Debug|x64.Build.0 = Debug|x64 18 | {D93780D5-87B8-4E91-A28D-9F4A8FAE657E}.Debug|x86.ActiveCfg = Debug|Win32 19 | {D93780D5-87B8-4E91-A28D-9F4A8FAE657E}.Debug|x86.Build.0 = Debug|Win32 20 | {D93780D5-87B8-4E91-A28D-9F4A8FAE657E}.Release|x64.ActiveCfg = Release|x64 21 | {D93780D5-87B8-4E91-A28D-9F4A8FAE657E}.Release|x64.Build.0 = Release|x64 22 | {D93780D5-87B8-4E91-A28D-9F4A8FAE657E}.Release|x86.ActiveCfg = Release|Win32 23 | {D93780D5-87B8-4E91-A28D-9F4A8FAE657E}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {D7D163D8-D9FF-4D68-8D66-6748567DB961} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter08/Section_8.2/CountingSort/CountingSort.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter08/Section_8.2/CountingSort/CountingSort.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter08/Section_8.2/CountingSort/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "CountingSort.h" 3 | 4 | using namespace std; 5 | 6 | void print_array(int data[], int n) 7 | { 8 | for (int i = 0; i < n; ++i) 9 | cout << data[i] << " "; 10 | cout << "\n"; 11 | } 12 | 13 | int main() 14 | { 15 | int array1[] = { 2, 5, 3, -1, 2, 3, -2, 3, -3, -7 }; 16 | counting_sort(array1, sizeof(array1)/sizeof(int)); 17 | print_array(array1, sizeof(array1)/sizeof(int)); 18 | 19 | int array2[] = { 6, 0, 2, 0, 1, 3, 4, 6, 1, 3, 2 }; 20 | counting_sort(array2, sizeof(array2)/sizeof(int)); 21 | print_array(array2, sizeof(array2)/sizeof(int)); 22 | 23 | int array3[] = { -1, -1, -1, -1 }; 24 | counting_sort(array3, sizeof(array3)/sizeof(int)); 25 | print_array(array3, sizeof(array3)/sizeof(int)); 26 | 27 | int array4[] ={ -7, -7 }; 28 | counting_sort(array4, sizeof(array4)/sizeof(int)); 29 | print_array(array4, sizeof(array4)/sizeof(int)); 30 | 31 | int array5[] ={ 20, -100 }; 32 | counting_sort(array5, sizeof(array5)/sizeof(int)); 33 | print_array(array5, sizeof(array5)/sizeof(int)); 34 | 35 | int array6[] ={ 20 }; 36 | counting_sort(array6, sizeof(array6)/sizeof(int)); 37 | print_array(array6, sizeof(array6)/sizeof(int)); 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Chapter08/Section_8.3/RadixSort/.vs/RadixSort/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter08/Section_8.3/RadixSort/.vs/RadixSort/v16/.suo -------------------------------------------------------------------------------- /Chapter08/Section_8.3/RadixSort/RadixSort.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29424.173 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RadixSort", "RadixSort.vcxproj", "{28257A9D-C9B7-4A6E-9120-C726C0AE9904}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {28257A9D-C9B7-4A6E-9120-C726C0AE9904}.Debug|x64.ActiveCfg = Debug|x64 17 | {28257A9D-C9B7-4A6E-9120-C726C0AE9904}.Debug|x64.Build.0 = Debug|x64 18 | {28257A9D-C9B7-4A6E-9120-C726C0AE9904}.Debug|x86.ActiveCfg = Debug|Win32 19 | {28257A9D-C9B7-4A6E-9120-C726C0AE9904}.Debug|x86.Build.0 = Debug|Win32 20 | {28257A9D-C9B7-4A6E-9120-C726C0AE9904}.Release|x64.ActiveCfg = Release|x64 21 | {28257A9D-C9B7-4A6E-9120-C726C0AE9904}.Release|x64.Build.0 = Release|x64 22 | {28257A9D-C9B7-4A6E-9120-C726C0AE9904}.Release|x86.ActiveCfg = Release|Win32 23 | {28257A9D-C9B7-4A6E-9120-C726C0AE9904}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {2C3AAEAE-23DE-444B-B60D-858303F21F9F} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter08/Section_8.3/RadixSort/RadixSort.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 头文件 20 | 21 | 22 | 23 | 24 | 源文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter08/Section_8.3/RadixSort/RadixSort.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter08/Section_8.3/RadixSort/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "RadixSort.h" 3 | 4 | using namespace std; 5 | 6 | template 7 | void print_array(T data[], int n) 8 | { 9 | for (int i = 0; i < n; ++i) 10 | cout << "0x" << hex << (unsigned long)data[i] << " "; 11 | cout << "\n"; 12 | } 13 | 14 | int main() 15 | { 16 | int array1[] ={ 0x329, 0x457, 0x657, 0x839, 0x436, 0x720, 0x355 }; 17 | radix_sort(array1, sizeof(array1)/sizeof(int), 8); 18 | print_array(array1, sizeof(array1)/sizeof(int)); 19 | 20 | unsigned char array2[] ={ 0x29, 0x57, 0x57, 0x39, 0x36, 0x20, 0x55 }; 21 | radix_sort(array2, sizeof(array2)/sizeof(unsigned char), 2); 22 | print_array(array2, sizeof(array2)/sizeof(unsigned char)); 23 | 24 | int array3[] ={ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02 }; 25 | radix_sort(array3, sizeof(array3)/sizeof(int), 16); 26 | print_array(array3, sizeof(array3)/sizeof(int)); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Chapter08/Section_8.4/BucketSort/.vs/BucketSort/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter08/Section_8.4/BucketSort/.vs/BucketSort/v16/.suo -------------------------------------------------------------------------------- /Chapter08/Section_8.4/BucketSort/BucketSort.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29519.181 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BucketSort", "BucketSort.vcxproj", "{8975FDC9-F99A-4D9C-8661-4D4E8D99F9A1}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {8975FDC9-F99A-4D9C-8661-4D4E8D99F9A1}.Debug|x64.ActiveCfg = Debug|x64 17 | {8975FDC9-F99A-4D9C-8661-4D4E8D99F9A1}.Debug|x64.Build.0 = Debug|x64 18 | {8975FDC9-F99A-4D9C-8661-4D4E8D99F9A1}.Debug|x86.ActiveCfg = Debug|Win32 19 | {8975FDC9-F99A-4D9C-8661-4D4E8D99F9A1}.Debug|x86.Build.0 = Debug|Win32 20 | {8975FDC9-F99A-4D9C-8661-4D4E8D99F9A1}.Release|x64.ActiveCfg = Release|x64 21 | {8975FDC9-F99A-4D9C-8661-4D4E8D99F9A1}.Release|x64.Build.0 = Release|x64 22 | {8975FDC9-F99A-4D9C-8661-4D4E8D99F9A1}.Release|x86.ActiveCfg = Release|Win32 23 | {8975FDC9-F99A-4D9C-8661-4D4E8D99F9A1}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {1C6807F8-72BD-432F-8ADD-00892E6D36D0} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter08/Section_8.4/BucketSort/BucketSort.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | 头文件 28 | 29 | 30 | -------------------------------------------------------------------------------- /Chapter09/Section_9.1/Exercise_9.1-1/FindSecondMin/.vs/FindSecondMin/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter09/Section_9.1/Exercise_9.1-1/FindSecondMin/.vs/FindSecondMin/v16/.suo -------------------------------------------------------------------------------- /Chapter09/Section_9.1/Exercise_9.1-1/FindSecondMin/FindSecondMin.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29926.136 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FindSecondMin", "FindSecondMin.vcxproj", "{3AB0D793-9DF7-46C6-A404-99020DDA74F1}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {3AB0D793-9DF7-46C6-A404-99020DDA74F1}.Debug|x64.ActiveCfg = Debug|x64 17 | {3AB0D793-9DF7-46C6-A404-99020DDA74F1}.Debug|x64.Build.0 = Debug|x64 18 | {3AB0D793-9DF7-46C6-A404-99020DDA74F1}.Debug|x86.ActiveCfg = Debug|Win32 19 | {3AB0D793-9DF7-46C6-A404-99020DDA74F1}.Debug|x86.Build.0 = Debug|Win32 20 | {3AB0D793-9DF7-46C6-A404-99020DDA74F1}.Release|x64.ActiveCfg = Release|x64 21 | {3AB0D793-9DF7-46C6-A404-99020DDA74F1}.Release|x64.Build.0 = Release|x64 22 | {3AB0D793-9DF7-46C6-A404-99020DDA74F1}.Release|x86.ActiveCfg = Release|Win32 23 | {3AB0D793-9DF7-46C6-A404-99020DDA74F1}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {8E43B97E-07D6-4683-82F6-CF59A8AAC17C} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter09/Section_9.1/Exercise_9.1-1/FindSecondMin/FindSecondMin.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter09/Section_9.1/Exercise_9.1-1/FindSecondMin/FindSecondMin.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter09/Section_9.1/Exercise_9.1-2/FindMinMaxRandom/.vs/FindMinMaxRandom/FileContentIndex/6e270b03-c3af-4078-8d84-c35c2686f6ab.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter09/Section_9.1/Exercise_9.1-2/FindMinMaxRandom/.vs/FindMinMaxRandom/FileContentIndex/6e270b03-c3af-4078-8d84-c35c2686f6ab.vsidx -------------------------------------------------------------------------------- /Chapter09/Section_9.1/Exercise_9.1-2/FindMinMaxRandom/.vs/FindMinMaxRandom/FileContentIndex/c345ef06-7cca-4928-8520-ce952861cc38.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter09/Section_9.1/Exercise_9.1-2/FindMinMaxRandom/.vs/FindMinMaxRandom/FileContentIndex/c345ef06-7cca-4928-8520-ce952861cc38.vsidx -------------------------------------------------------------------------------- /Chapter09/Section_9.1/Exercise_9.1-2/FindMinMaxRandom/.vs/FindMinMaxRandom/FileContentIndex/read.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter09/Section_9.1/Exercise_9.1-2/FindMinMaxRandom/.vs/FindMinMaxRandom/FileContentIndex/read.lock -------------------------------------------------------------------------------- /Chapter09/Section_9.1/Exercise_9.1-2/FindMinMaxRandom/.vs/FindMinMaxRandom/v17/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter09/Section_9.1/Exercise_9.1-2/FindMinMaxRandom/.vs/FindMinMaxRandom/v17/.suo -------------------------------------------------------------------------------- /Chapter09/Section_9.1/Exercise_9.1-2/FindMinMaxRandom/FindMinMaxRandom.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.4.33213.308 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FindMinMaxRandom", "FindMinMaxRandom.vcxproj", "{1B26F3D7-4231-4931-B515-EE1D7FEA2F49}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {1B26F3D7-4231-4931-B515-EE1D7FEA2F49}.Debug|x64.ActiveCfg = Debug|x64 17 | {1B26F3D7-4231-4931-B515-EE1D7FEA2F49}.Debug|x64.Build.0 = Debug|x64 18 | {1B26F3D7-4231-4931-B515-EE1D7FEA2F49}.Debug|x86.ActiveCfg = Debug|Win32 19 | {1B26F3D7-4231-4931-B515-EE1D7FEA2F49}.Debug|x86.Build.0 = Debug|Win32 20 | {1B26F3D7-4231-4931-B515-EE1D7FEA2F49}.Release|x64.ActiveCfg = Release|x64 21 | {1B26F3D7-4231-4931-B515-EE1D7FEA2F49}.Release|x64.Build.0 = Release|x64 22 | {1B26F3D7-4231-4931-B515-EE1D7FEA2F49}.Release|x86.ActiveCfg = Release|Win32 23 | {1B26F3D7-4231-4931-B515-EE1D7FEA2F49}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {06383C3B-BB27-4DB7-A43A-96431314AF6E} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter09/Section_9.1/Exercise_9.1-2/FindMinMaxRandom/FindMinMaxRandom.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 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter09/Section_9.1/Exercise_9.1-2/FindMinMaxRandom/FindMinMaxRandom.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter09/Section_9.1/FindMinMax/.vs/FindMinMax/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter09/Section_9.1/FindMinMax/.vs/FindMinMax/v16/.suo -------------------------------------------------------------------------------- /Chapter09/Section_9.1/FindMinMax/FindMinMax.h: -------------------------------------------------------------------------------- 1 | #ifndef _FIND_MIN_MAX_ 2 | #define _FIND_MIN_MAX_ 3 | 4 | template 5 | void FindMinMax(T data[], int n, int &minId, int &maxId) 6 | { 7 | if (data == NULL || n < 1) 8 | { 9 | minId = -1; 10 | maxId = -1; 11 | } 12 | else 13 | { 14 | int i = 0; 15 | 16 | if ((n & 1) == 1) 17 | { 18 | minId = 0; 19 | maxId = 0; 20 | i = 1; 21 | } 22 | else 23 | { 24 | if (data[0] <= data[1]) 25 | { 26 | minId = 0; 27 | maxId = 1; 28 | } 29 | else 30 | { 31 | minId = 1; 32 | maxId = 0; 33 | } 34 | 35 | i = 2; 36 | } 37 | 38 | while (i < n) 39 | { 40 | if (data[i] <= data[i+1]) 41 | { 42 | if (data[i] < data[minId]) 43 | minId = i; 44 | if (data[i+1] > data[maxId]) 45 | maxId = i+1; 46 | } 47 | else 48 | { 49 | if (data[i+1] < data[minId]) 50 | minId = i+1; 51 | if (data[i] > data[maxId]) 52 | maxId = i; 53 | } 54 | 55 | i += 2; 56 | } 57 | } 58 | } 59 | 60 | #endif // #ifndef _FIND_MIN_MAX_ 61 | -------------------------------------------------------------------------------- /Chapter09/Section_9.1/FindMinMax/FindMinMax.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30002.166 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FindMinMax", "FindMinMax.vcxproj", "{A47DCE91-55B4-41C7-97E5-74FDC6594FDD}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {A47DCE91-55B4-41C7-97E5-74FDC6594FDD}.Debug|x64.ActiveCfg = Debug|x64 17 | {A47DCE91-55B4-41C7-97E5-74FDC6594FDD}.Debug|x64.Build.0 = Debug|x64 18 | {A47DCE91-55B4-41C7-97E5-74FDC6594FDD}.Debug|x86.ActiveCfg = Debug|Win32 19 | {A47DCE91-55B4-41C7-97E5-74FDC6594FDD}.Debug|x86.Build.0 = Debug|Win32 20 | {A47DCE91-55B4-41C7-97E5-74FDC6594FDD}.Release|x64.ActiveCfg = Release|x64 21 | {A47DCE91-55B4-41C7-97E5-74FDC6594FDD}.Release|x64.Build.0 = Release|x64 22 | {A47DCE91-55B4-41C7-97E5-74FDC6594FDD}.Release|x86.ActiveCfg = Release|Win32 23 | {A47DCE91-55B4-41C7-97E5-74FDC6594FDD}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {4DFDAE0B-0B9B-4813-A25A-7FE09C2F8FFD} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter09/Section_9.1/FindMinMax/FindMinMax.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;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 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter09/Section_9.1/FindMinMax/FindMinMax.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter09/Section_9.1/FindMinMax/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "FindMinMax.h" 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int a[] = { 3, 6, 1, -1, 0, 100, 58 }; 10 | int aMinId, aMaxId; 11 | FindMinMax(a, sizeof(a)/sizeof(int), aMinId, aMaxId); 12 | cout << "aMinId = " << aMinId << ", aMaxId = " << aMaxId << "\n"; 13 | 14 | int b[] ={ 3, 6, 1, -1, 0, 100, 58, -32 }; 15 | int bMinId, bMaxId; 16 | FindMinMax(b, sizeof(b)/sizeof(int), bMinId, bMaxId); 17 | cout << "bMinId = " << bMinId << ", bMaxId = " << bMaxId << "\n"; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/.vs/InvestPlanDemo/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-10/InvestPlanDemo/.vs/InvestPlanDemo/v15/.suo -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanAlgo.h: -------------------------------------------------------------------------------- 1 | #ifndef _INVEST_PLAN_ALGO_H_ 2 | #define _INVEST_PLAN_ALGO_H_ 3 | 4 | class InvestPlan 5 | { 6 | public: 7 | InvestPlan(); 8 | ~InvestPlan(); 9 | 10 | void Clear(); 11 | bool SetParameters(int y, int i, int f1, int f2, int im); 12 | void GenerateRandomRate(); 13 | bool CreateInvestPlan(); 14 | 15 | const int GetYears() const { return years; } 16 | const int GetInvestments() const { return investments; } 17 | const double GetTotalIncome() const { return totalIncome; } 18 | const int* GetRatePercent() const { return ratePercent; } 19 | const int* GetInvestSelect() const { return investSelect; } 20 | 21 | private: 22 | int years; 23 | int investments; 24 | int fee1; 25 | int fee2; 26 | int initialMoney; 27 | double totalIncome; 28 | int *ratePercent; 29 | int *investSelect; 30 | }; 31 | 32 | #endif // #ifndef _INVEST_PLAN_ALGO_H_ 33 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanDemo.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanDemo.aps -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanDemo.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanDemo.cpp -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanDemo.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanDemo.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanDemo.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanDemo.rc -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "InvestPlanDemo", "InvestPlanDemo.vcxproj", "{94B8E42B-7299-45E3-BD17-7BF1D5447D6F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {94B8E42B-7299-45E3-BD17-7BF1D5447D6F}.Debug|x64.ActiveCfg = Debug|x64 17 | {94B8E42B-7299-45E3-BD17-7BF1D5447D6F}.Debug|x64.Build.0 = Debug|x64 18 | {94B8E42B-7299-45E3-BD17-7BF1D5447D6F}.Debug|x86.ActiveCfg = Debug|Win32 19 | {94B8E42B-7299-45E3-BD17-7BF1D5447D6F}.Debug|x86.Build.0 = Debug|Win32 20 | {94B8E42B-7299-45E3-BD17-7BF1D5447D6F}.Release|x64.ActiveCfg = Release|x64 21 | {94B8E42B-7299-45E3-BD17-7BF1D5447D6F}.Release|x64.Build.0 = Release|x64 22 | {94B8E42B-7299-45E3-BD17-7BF1D5447D6F}.Release|x86.ActiveCfg = Release|Win32 23 | {94B8E42B-7299-45E3-BD17-7BF1D5447D6F}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {FFFCE2CF-5600-47C1-9438-26EE788DA35A} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanDemo.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | InvestPlanDemo.rc 5 | 6 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanDemoDlg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanDemoDlg.cpp -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanDemoDlg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanDemoDlg.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanView.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanView.cpp -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanView.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-10/InvestPlanDemo/InvestPlanView.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/res/InvestPlanDemo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-10/InvestPlanDemo/res/InvestPlanDemo.ico -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/res/InvestPlanDemo.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-10/InvestPlanDemo/res/InvestPlanDemo.rc2 -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-10/InvestPlanDemo/resource.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-10/InvestPlanDemo/stdafx.cpp -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-10/InvestPlanDemo/stdafx.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-10/InvestPlanDemo/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-10/InvestPlanDemo/targetver.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-2/LPS/.vs/LPS/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-2/LPS/.vs/LPS/v15/.suo -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-2/LPS/LPS.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2036 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LPS", "LPS.vcxproj", "{3EE94F8D-D895-4156-9BDF-6089F99DEA6F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {3EE94F8D-D895-4156-9BDF-6089F99DEA6F}.Debug|x64.ActiveCfg = Debug|x64 17 | {3EE94F8D-D895-4156-9BDF-6089F99DEA6F}.Debug|x64.Build.0 = Debug|x64 18 | {3EE94F8D-D895-4156-9BDF-6089F99DEA6F}.Debug|x86.ActiveCfg = Debug|Win32 19 | {3EE94F8D-D895-4156-9BDF-6089F99DEA6F}.Debug|x86.Build.0 = Debug|Win32 20 | {3EE94F8D-D895-4156-9BDF-6089F99DEA6F}.Release|x64.ActiveCfg = Release|x64 21 | {3EE94F8D-D895-4156-9BDF-6089F99DEA6F}.Release|x64.Build.0 = Release|x64 22 | {3EE94F8D-D895-4156-9BDF-6089F99DEA6F}.Release|x86.ActiveCfg = Release|Win32 23 | {3EE94F8D-D895-4156-9BDF-6089F99DEA6F}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {B70325C0-AFBC-4348-8888-E7C0312C72F1} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-2/LPS/LPS.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;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 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/.vs/MinBitonicPath/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-3/MinBitonicPath/.vs/MinBitonicPath/v15/.suo -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPath.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPath.aps -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPath.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPath.cpp -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPath.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPath.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPath.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPath.rc -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPath.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MinBitonicPath", "MinBitonicPath.vcxproj", "{F09DD747-4D50-4B24-8661-CBE33430B37E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {F09DD747-4D50-4B24-8661-CBE33430B37E}.Debug|x64.ActiveCfg = Debug|x64 17 | {F09DD747-4D50-4B24-8661-CBE33430B37E}.Debug|x64.Build.0 = Debug|x64 18 | {F09DD747-4D50-4B24-8661-CBE33430B37E}.Debug|x86.ActiveCfg = Debug|Win32 19 | {F09DD747-4D50-4B24-8661-CBE33430B37E}.Debug|x86.Build.0 = Debug|Win32 20 | {F09DD747-4D50-4B24-8661-CBE33430B37E}.Release|x64.ActiveCfg = Release|x64 21 | {F09DD747-4D50-4B24-8661-CBE33430B37E}.Release|x64.Build.0 = Release|x64 22 | {F09DD747-4D50-4B24-8661-CBE33430B37E}.Release|x86.ActiveCfg = Release|Win32 23 | {F09DD747-4D50-4B24-8661-CBE33430B37E}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {E3B794A6-7575-42B2-92FA-E346830353B9} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPath.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | MinBitonicPath.rc 5 | 6 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPathAlgo.h: -------------------------------------------------------------------------------- 1 | #ifndef _MIN_BITONIC_PATH_ALGO_H_ 2 | #define _MIN_BITONIC_PATH_ALGO_H_ 3 | 4 | double GetMinBitonicPath(CPoint sortedPoint[], int n, int pointChain[]); 5 | 6 | #endif // _MIN_BITONIC_PATH_ALGO_H_ 7 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPathDlg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPathDlg.cpp -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPathDlg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPathDlg.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPathView.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPathView.cpp -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPathView.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-3/MinBitonicPath/MinBitonicPathView.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/res/MinBitonicPath.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-3/MinBitonicPath/res/MinBitonicPath.ico -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/res/MinBitonicPath.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-3/MinBitonicPath/res/MinBitonicPath.rc2 -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-3/MinBitonicPath/resource.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-3/MinBitonicPath/stdafx.cpp -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-3/MinBitonicPath/stdafx.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-3/MinBitonicPath/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-3/MinBitonicPath/targetver.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-4/NeatlyPrint/.vs/NeatlyPrint/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-4/NeatlyPrint/.vs/NeatlyPrint/v15/.suo -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-4/NeatlyPrint/NeatlyPrint.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NeatlyPrint", "NeatlyPrint.vcxproj", "{1F1AA121-C535-41CD-BBA7-6738F10375AE}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {1F1AA121-C535-41CD-BBA7-6738F10375AE}.Debug|x64.ActiveCfg = Debug|x64 17 | {1F1AA121-C535-41CD-BBA7-6738F10375AE}.Debug|x64.Build.0 = Debug|x64 18 | {1F1AA121-C535-41CD-BBA7-6738F10375AE}.Debug|x86.ActiveCfg = Debug|Win32 19 | {1F1AA121-C535-41CD-BBA7-6738F10375AE}.Debug|x86.Build.0 = Debug|Win32 20 | {1F1AA121-C535-41CD-BBA7-6738F10375AE}.Release|x64.ActiveCfg = Release|x64 21 | {1F1AA121-C535-41CD-BBA7-6738F10375AE}.Release|x64.Build.0 = Release|x64 22 | {1F1AA121-C535-41CD-BBA7-6738F10375AE}.Release|x86.ActiveCfg = Release|Win32 23 | {1F1AA121-C535-41CD-BBA7-6738F10375AE}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {59945690-99A0-4CA9-AF53-B13ABB99C7A0} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-4/NeatlyPrint/NeatlyPrint.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 26 | 27 | 头文件 28 | 29 | 30 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-4/NeatlyPrint/NeatlyPrint.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-4/NeatlyPrint/NeatlyPrintAlgo.h: -------------------------------------------------------------------------------- 1 | #ifndef _NEATLY_PRINT_ALGO_H_ 2 | #define _NEATLY_PRINT_ALGO_H_ 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | int NeatlyPrint(const string &inFileName, int lineCapacity, const string &outFileName); 9 | 10 | 11 | #endif // #ifndef _NEATLY_PRINT_ALGO_H_ 12 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-4/NeatlyPrint/input.txt: -------------------------------------------------------------------------------- 1 | If you wish to implement any of the algorithms, you should find the translation 2 | of our pseudocode into your favorite programming language to be a fairly 3 | straightforward task. We have designed the pseudocode to present each algorithm 4 | clearly and succinctly. Consequently, we do not address error-handling and other 5 | software-engineering issues that require specific assumptions about your programming 6 | environment. We attempt to present each algorithm simply and directly without 7 | allowing the idiosyncrasies of a particular programming language to obscure 8 | its essence. -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-4/NeatlyPrint/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "NeatlyPrintAlgo.h" 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | NeatlyPrint("input.txt", 64, "output.txt"); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/DNAAlign/.vs/DNAAlign/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-5/DNAAlign/.vs/DNAAlign/v15/.suo -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/DNAAlign/DNAAlign.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DNAAlign", "DNAAlign.vcxproj", "{17F92F24-0AF4-4FCE-86DC-8A486F87AA69}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {17F92F24-0AF4-4FCE-86DC-8A486F87AA69}.Debug|x64.ActiveCfg = Debug|x64 17 | {17F92F24-0AF4-4FCE-86DC-8A486F87AA69}.Debug|x64.Build.0 = Debug|x64 18 | {17F92F24-0AF4-4FCE-86DC-8A486F87AA69}.Debug|x86.ActiveCfg = Debug|Win32 19 | {17F92F24-0AF4-4FCE-86DC-8A486F87AA69}.Debug|x86.Build.0 = Debug|Win32 20 | {17F92F24-0AF4-4FCE-86DC-8A486F87AA69}.Release|x64.ActiveCfg = Release|x64 21 | {17F92F24-0AF4-4FCE-86DC-8A486F87AA69}.Release|x64.Build.0 = Release|x64 22 | {17F92F24-0AF4-4FCE-86DC-8A486F87AA69}.Release|x86.ActiveCfg = Release|Win32 23 | {17F92F24-0AF4-4FCE-86DC-8A486F87AA69}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {85336619-8082-4265-90E1-4806B14D4783} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/DNAAlign/DNAAlign.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/DNAAlign/DNAAlign.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/.vs/EditDistance/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-5/EditDistance/.vs/EditDistance/v15/.suo -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/EditDistance.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-5/EditDistance/EditDistance.aps -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/EditDistance.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-5/EditDistance/EditDistance.cpp -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/EditDistance.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-5/EditDistance/EditDistance.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/EditDistance.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-5/EditDistance/EditDistance.rc -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/EditDistance.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EditDistance", "EditDistance.vcxproj", "{0B7C990C-B181-4423-92E3-D4F7F9CAF2CB}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {0B7C990C-B181-4423-92E3-D4F7F9CAF2CB}.Debug|x64.ActiveCfg = Debug|x64 17 | {0B7C990C-B181-4423-92E3-D4F7F9CAF2CB}.Debug|x64.Build.0 = Debug|x64 18 | {0B7C990C-B181-4423-92E3-D4F7F9CAF2CB}.Debug|x86.ActiveCfg = Debug|Win32 19 | {0B7C990C-B181-4423-92E3-D4F7F9CAF2CB}.Debug|x86.Build.0 = Debug|Win32 20 | {0B7C990C-B181-4423-92E3-D4F7F9CAF2CB}.Release|x64.ActiveCfg = Release|x64 21 | {0B7C990C-B181-4423-92E3-D4F7F9CAF2CB}.Release|x64.Build.0 = Release|x64 22 | {0B7C990C-B181-4423-92E3-D4F7F9CAF2CB}.Release|x86.ActiveCfg = Release|Win32 23 | {0B7C990C-B181-4423-92E3-D4F7F9CAF2CB}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {FF86878C-40F6-4C84-B16C-1E1E329E1D9A} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/EditDistance.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | EditDistance.rc 5 | 6 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/EditDistanceAlgo.h: -------------------------------------------------------------------------------- 1 | #ifndef _EDIT_DISTANCE_ALGO_H_ 2 | #define _EDIT_DISTANCE_ALGO_H_ 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | enum OperationType 10 | { 11 | OP_NONE = -1, 12 | OP_COPY = 0, 13 | OP_REPLACE, 14 | OP_DELETE, 15 | OP_INSERT, 16 | OP_TWIDDLE, 17 | OP_KILL 18 | }; 19 | 20 | class EditDistance 21 | { 22 | public: 23 | const string& GetOriginalString() const { return originalStr; } 24 | const string& GetTargetString() const { return targetStr; } 25 | const vector& GetOPChain() const { return opChain; } 26 | double GetEditDistance(const string &str1, const string &str2, const double opCost[6]); 27 | void Clear(); 28 | 29 | private: 30 | string originalStr; 31 | string targetStr; 32 | vector opChain; 33 | }; 34 | 35 | #endif // _EDIT_DISTANCE_ALGO_H_ 36 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/EditDistanceDlg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-5/EditDistance/EditDistanceDlg.cpp -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/EditDistanceDlg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-5/EditDistance/EditDistanceDlg.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/TransferView.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-5/EditDistance/TransferView.cpp -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/TransferView.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-5/EditDistance/TransferView.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/res/EditDistance.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-5/EditDistance/res/EditDistance.ico -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/res/EditDistance.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-5/EditDistance/res/EditDistance.rc2 -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-5/EditDistance/resource.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-5/EditDistance/stdafx.cpp -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-5/EditDistance/stdafx.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-5/EditDistance/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-5/EditDistance/targetver.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/.vs/ImageSeamDemo/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-8/ImageSeamDemo/.vs/ImageSeamDemo/v15/.suo -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/CImageSeamView.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-8/ImageSeamDemo/CImageSeamView.cpp -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/CImageSeamView.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-8/ImageSeamDemo/CImageSeamView.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/ImageSeam.h: -------------------------------------------------------------------------------- 1 | #ifndef _IMAGE_SEAM_H_ 2 | #define _IMAGE_SEAM_H_ 3 | 4 | 5 | class ImageSeam 6 | { 7 | public: 8 | ImageSeam(); 9 | ImageSeam(int w, int h); 10 | ~ImageSeam(); 11 | 12 | bool SetSize(int w, int h); 13 | void Clear(); 14 | void GenerateRandomDisruption(); 15 | bool SetDisruption(int x, int y, unsigned char d); 16 | const int GetWidth() const { return width; } 17 | const int GetHeight() const { return height; } 18 | const unsigned char GetDisruption(int x, int y) const; 19 | const int GetTotalDisruption() const { return totalDisruption; } 20 | bool BuildImageSeam(); 21 | 22 | const unsigned char* GetDisruptionBuffer() const { return disruption; } 23 | const int* GetSeamChainBuffer() const { return seamChain; } 24 | 25 | static const int DISRUPTION_MAX = 100; 26 | 27 | private: 28 | int width; 29 | int height; 30 | unsigned char *disruption; 31 | int *seamChain; 32 | int totalDisruption; 33 | }; 34 | 35 | 36 | #endif // #ifndef _IMAGE_SEAM_H_#pragma once 37 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/ImageSeamDemo.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-8/ImageSeamDemo/ImageSeamDemo.aps -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/ImageSeamDemo.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-8/ImageSeamDemo/ImageSeamDemo.cpp -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/ImageSeamDemo.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-8/ImageSeamDemo/ImageSeamDemo.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/ImageSeamDemo.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-8/ImageSeamDemo/ImageSeamDemo.rc -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/ImageSeamDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2050 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImageSeamDemo", "ImageSeamDemo.vcxproj", "{EE7F3A84-B8DE-4DE0-82E9-D747DC23C8F1}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {EE7F3A84-B8DE-4DE0-82E9-D747DC23C8F1}.Debug|x64.ActiveCfg = Debug|x64 17 | {EE7F3A84-B8DE-4DE0-82E9-D747DC23C8F1}.Debug|x64.Build.0 = Debug|x64 18 | {EE7F3A84-B8DE-4DE0-82E9-D747DC23C8F1}.Debug|x86.ActiveCfg = Debug|Win32 19 | {EE7F3A84-B8DE-4DE0-82E9-D747DC23C8F1}.Debug|x86.Build.0 = Debug|Win32 20 | {EE7F3A84-B8DE-4DE0-82E9-D747DC23C8F1}.Release|x64.ActiveCfg = Release|x64 21 | {EE7F3A84-B8DE-4DE0-82E9-D747DC23C8F1}.Release|x64.Build.0 = Release|x64 22 | {EE7F3A84-B8DE-4DE0-82E9-D747DC23C8F1}.Release|x86.ActiveCfg = Release|Win32 23 | {EE7F3A84-B8DE-4DE0-82E9-D747DC23C8F1}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {2742BFF5-9AD5-4FE4-A8B4-5550EC6118A1} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/ImageSeamDemo.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | ImageSeamDemo.rc 5 | 6 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/ImageSeamDemoDlg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-8/ImageSeamDemo/ImageSeamDemoDlg.cpp -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/ImageSeamDemoDlg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-8/ImageSeamDemo/ImageSeamDemoDlg.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/res/ImageSeamDemo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-8/ImageSeamDemo/res/ImageSeamDemo.ico -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/res/ImageSeamDemo.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-8/ImageSeamDemo/res/ImageSeamDemo.rc2 -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-8/ImageSeamDemo/resource.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-8/ImageSeamDemo/stdafx.cpp -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-8/ImageSeamDemo/stdafx.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-8/ImageSeamDemo/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-8/ImageSeamDemo/targetver.h -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-9/StringSplitDemo/.vs/StringSplitDemo/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Problems/Problem_15-9/StringSplitDemo/.vs/StringSplitDemo/v15/.suo -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-9/StringSplitDemo/StringSplitAlgo.h: -------------------------------------------------------------------------------- 1 | #ifndef _STRING_SPLIT_ALGO_H_ 2 | #define _STRING_SPLIT_ALGO_H_ 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | class StringSplit 9 | { 10 | public: 11 | StringSplit(); 12 | ~StringSplit(); 13 | 14 | bool SetLengthPosition(int strLen, int splitPosNum, int splitPos[]); 15 | void Clear(); 16 | bool GenerateSplitOrder(); 17 | const int GetStrLength() const { return strLength; } 18 | const vector& GetsplitOrder() const { return splitOrder; } 19 | 20 | private: 21 | int strLength; 22 | int splitPositionNumber; 23 | int *splitPosition; 24 | vector splitOrder; 25 | 26 | void SaveSplitOrder(const int *splitPos, int **sp, int i, int j, vector &spOrder); 27 | }; 28 | 29 | #endif // #ifndef _STRING_SPLIT_ALGO_H_ 30 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-9/StringSplitDemo/StringSplitDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2050 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StringSplitDemo", "StringSplitDemo.vcxproj", "{79C0CF49-9E04-432A-824F-C63852783E0A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {79C0CF49-9E04-432A-824F-C63852783E0A}.Debug|x64.ActiveCfg = Debug|x64 17 | {79C0CF49-9E04-432A-824F-C63852783E0A}.Debug|x64.Build.0 = Debug|x64 18 | {79C0CF49-9E04-432A-824F-C63852783E0A}.Debug|x86.ActiveCfg = Debug|Win32 19 | {79C0CF49-9E04-432A-824F-C63852783E0A}.Debug|x86.Build.0 = Debug|Win32 20 | {79C0CF49-9E04-432A-824F-C63852783E0A}.Release|x64.ActiveCfg = Release|x64 21 | {79C0CF49-9E04-432A-824F-C63852783E0A}.Release|x64.Build.0 = Release|x64 22 | {79C0CF49-9E04-432A-824F-C63852783E0A}.Release|x86.ActiveCfg = Release|Win32 23 | {79C0CF49-9E04-432A-824F-C63852783E0A}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {EF162A99-4E2B-4A8B-A4F8-643642E1BA6B} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-9/StringSplitDemo/StringSplitDemo.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 26 | 27 | 头文件 28 | 29 | 30 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-9/StringSplitDemo/StringSplitDemo.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter15/Problems/Problem_15-9/StringSplitDemo/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "StringSplitAlgo.h" 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int splitPos[] = { 9, 1, 7 }; // string index starts from 0 10 | StringSplit strSplit; 11 | 12 | strSplit.SetLengthPosition(20, sizeof(splitPos)/sizeof(int), splitPos); 13 | strSplit.GenerateSplitOrder(); 14 | 15 | for (unsigned int i = 0; i < strSplit.GetsplitOrder().size(); ++i) 16 | { 17 | int sp = strSplit.GetsplitOrder()[i]; 18 | cout << "step_" << setw(2) << setfill('0') << i << "\t\t"; 19 | cout << "split_pos = " << sp << "\n"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Chapter15/Section_15.1/RodCut/.vs/RodCut/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.1/RodCut/.vs/RodCut/v15/.suo -------------------------------------------------------------------------------- /Chapter15/Section_15.1/RodCut/RodCut.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2036 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RodCut", "RodCut.vcxproj", "{7E160B31-80CF-403B-981E-74CA929073AF}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {7E160B31-80CF-403B-981E-74CA929073AF}.Debug|x64.ActiveCfg = Debug|x64 17 | {7E160B31-80CF-403B-981E-74CA929073AF}.Debug|x64.Build.0 = Debug|x64 18 | {7E160B31-80CF-403B-981E-74CA929073AF}.Debug|x86.ActiveCfg = Debug|Win32 19 | {7E160B31-80CF-403B-981E-74CA929073AF}.Debug|x86.Build.0 = Debug|Win32 20 | {7E160B31-80CF-403B-981E-74CA929073AF}.Release|x64.ActiveCfg = Release|x64 21 | {7E160B31-80CF-403B-981E-74CA929073AF}.Release|x64.Build.0 = Release|x64 22 | {7E160B31-80CF-403B-981E-74CA929073AF}.Release|x86.ActiveCfg = Release|Win32 23 | {7E160B31-80CF-403B-981E-74CA929073AF}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {AA027978-D128-443F-93A0-31CE2ED37E4C} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter15/Section_15.1/RodCut/RodCut.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;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 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter15/Section_15.1/RodCut/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // rod_length: [ 1 2 3 4 5 6 7 8 9 10] 6 | // rod_price: [ 1 5 8 9 10 17 17 20 24 30] 7 | const int priceTable[10] = {1, 3, 8, 9, 10, 17, 17, 20, 24, 30}; 8 | 9 | void RodCut(const int price[], int priceTableSize, int rodLen) 10 | { 11 | if(price == NULL || priceTableSize <= 0 || rodLen <= 0) 12 | cout << "Invalidate parameter!\n"; 13 | 14 | int *profit = new int[rodLen]; 15 | int *cutPos = new int[rodLen]; 16 | 17 | for(int i = 0; i < rodLen; ++i) 18 | { 19 | int maxProfit = INT_MIN; 20 | int optimalCutPos; 21 | 22 | for(int j = 0; j <= i && j < priceTableSize; ++j) 23 | { 24 | int curProfit; 25 | if(j == i) curProfit = price[j]; 26 | else curProfit = price[j] + profit[i-j-1]; 27 | 28 | if(maxProfit < curProfit) 29 | { 30 | maxProfit = curProfit; 31 | optimalCutPos = j; 32 | } 33 | } 34 | 35 | profit[i] = maxProfit; 36 | cutPos[i] = optimalCutPos+1; 37 | } 38 | 39 | cout << "Cutting Strategy: "; 40 | for(int i = rodLen-1; i >= 0; i -= cutPos[i]) 41 | cout << cutPos[i] << " "; 42 | cout << "\n"; 43 | 44 | cout << "Total profit: " << profit[rodLen-1] << "\n"; 45 | 46 | delete[] profit; 47 | delete[] cutPos; 48 | } 49 | 50 | int main() 51 | { 52 | while(1) 53 | { 54 | int rodLen; 55 | cout << "Please input a rod length: "; 56 | cin >> rodLen; 57 | RodCut(priceTable, sizeof(priceTable)/sizeof(int), rodLen); 58 | cout << "\n"; 59 | } 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /Chapter15/Section_15.2/MatrixChainOrder/.vs/MatrixChainOrder/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.2/MatrixChainOrder/.vs/MatrixChainOrder/v15/.suo -------------------------------------------------------------------------------- /Chapter15/Section_15.2/MatrixChainOrder/MatrixChainOrder.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2036 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MatrixChainOrder", "MatrixChainOrder.vcxproj", "{B8D41DDA-634E-4265-A8AF-F408C4E0B2D0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {B8D41DDA-634E-4265-A8AF-F408C4E0B2D0}.Debug|x64.ActiveCfg = Debug|x64 17 | {B8D41DDA-634E-4265-A8AF-F408C4E0B2D0}.Debug|x64.Build.0 = Debug|x64 18 | {B8D41DDA-634E-4265-A8AF-F408C4E0B2D0}.Debug|x86.ActiveCfg = Debug|Win32 19 | {B8D41DDA-634E-4265-A8AF-F408C4E0B2D0}.Debug|x86.Build.0 = Debug|Win32 20 | {B8D41DDA-634E-4265-A8AF-F408C4E0B2D0}.Release|x64.ActiveCfg = Release|x64 21 | {B8D41DDA-634E-4265-A8AF-F408C4E0B2D0}.Release|x64.Build.0 = Release|x64 22 | {B8D41DDA-634E-4265-A8AF-F408C4E0B2D0}.Release|x86.ActiveCfg = Release|Win32 23 | {B8D41DDA-634E-4265-A8AF-F408C4E0B2D0}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {AD60F72C-6CD1-4A57-A7A8-C174946C7B5B} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter15/Section_15.2/MatrixChainOrder/MatrixChainOrder.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;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 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter15/Section_15.4/Exercise_15.4-6/LMIS/.vs/LMIS/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.4/Exercise_15.4-6/LMIS/.vs/LMIS/v15/.suo -------------------------------------------------------------------------------- /Chapter15/Section_15.4/Exercise_15.4-6/LMIS/LMIS.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2036 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LMIS", "LMIS.vcxproj", "{B465A7B2-620E-4B44-A579-FB1CE0877EE5}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {B465A7B2-620E-4B44-A579-FB1CE0877EE5}.Debug|x64.ActiveCfg = Debug|x64 17 | {B465A7B2-620E-4B44-A579-FB1CE0877EE5}.Debug|x64.Build.0 = Debug|x64 18 | {B465A7B2-620E-4B44-A579-FB1CE0877EE5}.Debug|x86.ActiveCfg = Debug|Win32 19 | {B465A7B2-620E-4B44-A579-FB1CE0877EE5}.Debug|x86.Build.0 = Debug|Win32 20 | {B465A7B2-620E-4B44-A579-FB1CE0877EE5}.Release|x64.ActiveCfg = Release|x64 21 | {B465A7B2-620E-4B44-A579-FB1CE0877EE5}.Release|x64.Build.0 = Release|x64 22 | {B465A7B2-620E-4B44-A579-FB1CE0877EE5}.Release|x86.ActiveCfg = Release|Win32 23 | {B465A7B2-620E-4B44-A579-FB1CE0877EE5}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {05D00999-8D0F-4989-B8AE-43255F606C6A} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter15/Section_15.4/Exercise_15.4-6/LMIS/LMIS.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;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 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter15/Section_15.4/LCS/.vs/LCS/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.4/LCS/.vs/LCS/v15/.suo -------------------------------------------------------------------------------- /Chapter15/Section_15.4/LCS/LCS.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2036 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LCS", "LCS.vcxproj", "{2206A088-A925-4B59-8B0D-CBDA5571B7E9}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {2206A088-A925-4B59-8B0D-CBDA5571B7E9}.Debug|x64.ActiveCfg = Debug|x64 17 | {2206A088-A925-4B59-8B0D-CBDA5571B7E9}.Debug|x64.Build.0 = Debug|x64 18 | {2206A088-A925-4B59-8B0D-CBDA5571B7E9}.Debug|x86.ActiveCfg = Debug|Win32 19 | {2206A088-A925-4B59-8B0D-CBDA5571B7E9}.Debug|x86.Build.0 = Debug|Win32 20 | {2206A088-A925-4B59-8B0D-CBDA5571B7E9}.Release|x64.ActiveCfg = Release|x64 21 | {2206A088-A925-4B59-8B0D-CBDA5571B7E9}.Release|x64.Build.0 = Release|x64 22 | {2206A088-A925-4B59-8B0D-CBDA5571B7E9}.Release|x86.ActiveCfg = Release|Win32 23 | {2206A088-A925-4B59-8B0D-CBDA5571B7E9}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {7A1127B9-8B42-476E-A3F3-A03291E7C2D7} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter15/Section_15.4/LCS/LCS.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;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 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter15/Section_15.4/LCS/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define LCS_DIR_UP 0 6 | #define LCS_DIR_LEFT 1 7 | #define LCS_DIR_LEFT_UP 2 8 | 9 | void PrintLCS(unsigned char *pDir, int s2[], int n2, int i, int j, ostream &os) 10 | { 11 | if(i == 0 || j == 0) 12 | return; 13 | 14 | if(*pDir == LCS_DIR_LEFT_UP) 15 | { 16 | PrintLCS(pDir-n2-1, s2, n2, i-1, j-1, os); 17 | os << s2[j-1] << " "; 18 | } 19 | else 20 | { 21 | if(*pDir == LCS_DIR_UP) 22 | PrintLCS(pDir-n2, s2, n2, i-1, j, os); 23 | else 24 | PrintLCS(pDir-1, s2, n2, i, j-1, os); 25 | } 26 | } 27 | 28 | void LCS(int s1[], int n1, int s2[], int n2) 29 | { 30 | if(s1 == NULL || n1 <= 0 || s2 == NULL || n2 <= 0) 31 | return; 32 | 33 | int *lcsLen = new int[(n1+1)*(n2+1)]; 34 | unsigned char *lcsDir = new unsigned char[n1*n2]; 35 | 36 | for(int i = 0; i < n2+1; ++i) 37 | lcsLen[i] = 0; 38 | 39 | for(int i = n2+1; i < (n1+1)*(n2+1); i += (n2+1)) 40 | lcsLen[i] = 0; 41 | 42 | int *pLen = lcsLen + n2 + 2; 43 | unsigned char *pDir = lcsDir; 44 | 45 | for(int i = 0; i < n1; ++i) 46 | { 47 | for(int j = 0; j < n2; ++j) 48 | { 49 | if(s1[i] == s2[j]) 50 | { 51 | *pLen = *(pLen-n2-2) + 1; 52 | *pDir = LCS_DIR_LEFT_UP; 53 | } 54 | else 55 | { 56 | int leftLen = *(pLen-1); 57 | int upLen = *(pLen-n2-1); 58 | 59 | if(leftLen <= upLen) 60 | { 61 | *pLen = upLen; 62 | *pDir = LCS_DIR_UP; 63 | } 64 | else 65 | { 66 | *pLen = leftLen; 67 | *pDir = LCS_DIR_LEFT; 68 | } 69 | } 70 | 71 | ++pLen; 72 | ++pDir; 73 | } 74 | 75 | ++pLen; 76 | } 77 | 78 | PrintLCS(lcsDir+n1*n2-1, s2, n2, n1, n2, cout); 79 | 80 | delete[] lcsLen; 81 | delete[] lcsDir; 82 | } 83 | 84 | int main() 85 | { 86 | int s1[] = {1, 2, 3, 2, 4, 1, 2}; 87 | int s2[] = {2, 4, 3, 1, 2, 1}; 88 | 89 | LCS(s1, sizeof(s1)/sizeof(int), s2, sizeof(s2)/sizeof(int)); 90 | } 91 | -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/.vs/OptimalBST/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/.vs/OptimalBST/v15/.suo -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/OptimalBST.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/OptimalBST.aps -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/OptimalBST.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/OptimalBST.cpp -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/OptimalBST.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/OptimalBST.h -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/OptimalBST.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/OptimalBST.rc -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/OptimalBST.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2036 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OptimalBST", "OptimalBST.vcxproj", "{C0F91069-B30C-4AC2-8996-C57471819451}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {C0F91069-B30C-4AC2-8996-C57471819451}.Debug|x64.ActiveCfg = Debug|x64 17 | {C0F91069-B30C-4AC2-8996-C57471819451}.Debug|x64.Build.0 = Debug|x64 18 | {C0F91069-B30C-4AC2-8996-C57471819451}.Debug|x86.ActiveCfg = Debug|Win32 19 | {C0F91069-B30C-4AC2-8996-C57471819451}.Debug|x86.Build.0 = Debug|Win32 20 | {C0F91069-B30C-4AC2-8996-C57471819451}.Release|x64.ActiveCfg = Release|x64 21 | {C0F91069-B30C-4AC2-8996-C57471819451}.Release|x64.Build.0 = Release|x64 22 | {C0F91069-B30C-4AC2-8996-C57471819451}.Release|x86.ActiveCfg = Release|Win32 23 | {C0F91069-B30C-4AC2-8996-C57471819451}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {38B48E0C-F872-4896-BC70-312A7379D8B0} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/OptimalBST.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | OptimalBST.rc 5 | 6 | -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/OptimalBSTDlg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/OptimalBSTDlg.cpp -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/OptimalBSTDlg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/OptimalBSTDlg.h -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/OptimalBSTView.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/OptimalBSTView.cpp -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/OptimalBSTView.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/OptimalBSTView.h -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/OptimalBinarySearchTree.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | #include "OptimalBinarySearchTree.h" 4 | 5 | 6 | void OptimalBinarySearchTree::generate(int **root_index, int n) 7 | { 8 | clear(); 9 | generate(root, root_index, 0, n-1); 10 | } 11 | 12 | void OptimalBinarySearchTree::generate(BinaryTreeNode* &node, int **root_index, int i, int j) 13 | { 14 | int l = j-i; 15 | string str; 16 | char temp[10]; 17 | 18 | if(l >= 0) 19 | { 20 | str += "k"; 21 | _itoa_s(root_index[i][l]+1, temp, 10); 22 | str += temp; 23 | } 24 | else 25 | { 26 | str += "d"; 27 | _itoa_s(j+1, temp, 10); 28 | str += temp; 29 | } 30 | 31 | node = new BinaryTreeNode(str, NULL, NULL); 32 | 33 | if(l >= 0) 34 | { 35 | generate(node->left, root_index, i, root_index[i][l]-1); 36 | generate(node->right, root_index, root_index[i][l]+1, j); 37 | } 38 | else 39 | { 40 | return; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/res/OptimalBST.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/res/OptimalBST.ico -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/res/OptimalBST.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/res/OptimalBST.rc2 -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/res/Toolbar.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/res/Toolbar.bmp -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/res/Toolbar256.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/res/Toolbar256.bmp -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/resource.h -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/stdafx.cpp -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/stdafx.h -------------------------------------------------------------------------------- /Chapter15/Section_15.5/OptimalBST/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Chapter15/Section_15.5/OptimalBST/targetver.h -------------------------------------------------------------------------------- /Others/ComparisonSort/1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Others/ComparisonSort/1.bmp -------------------------------------------------------------------------------- /Others/ComparisonSort/2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Others/ComparisonSort/2.bmp -------------------------------------------------------------------------------- /Others/ComparisonSort/3.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Others/ComparisonSort/3.bmp -------------------------------------------------------------------------------- /Others/ComparisonSort/4.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangtzhou2012/Introduction_to_Algorithms_3rd/5cb4d79ddefc0fb53251adbc2424251db62c7a34/Others/ComparisonSort/4.bmp --------------------------------------------------------------------------------