STL模板,实现的堆排序功能
// range heap example
#include <iostream>
#include <algorithm> // std::make_heap, std::pop_heap, std::push_heap, std::sort_heap
#include <vector>
int main(){
int myints[] = {10, 20, 30, 5, 15};
std::vector<int> v(myints, myints + 5);
std::make_heap(v.begin(), v.end());
std::cout << "initial max heap:" << v.front() << '\n';
return 0;
}
ocr:
1:资源
tesseract https://github.com/teseract-ocr/tesseract
cppan https://github.com/tesseract-ocr/tessearct/wiki/Compiling#window
cmake https://cmake.org/download
2. 安装cmake,cppan。添加路径到系统环境变量
3. 运行cppan,运行cmake
linux:
编译leptonica
cd leptonica
autoreconf -vi
./autobuild
./configure
make
sudo make install
编译tesseract
cd tesseract
./autogen.sh
./configure
LDFLAGS ="-L/usr/local/lib" CFLAGS="-I/usr/local/include" cmake
sudo make install
sudo ldconfig
#include <iostream>
int g_array[] = {6, 1, 2, 7, 9, 10, 4, 5, 10, 8};
void adjust_heap(int target_array[], int node, int size){
int left = node * 2 + 1;
int right = node * 2 + 2;
int max = node;
if(left < size && target_array[left] > target_array[max]
{
max = left;
}
if(right < size && target_array[right] > target_array[max]){
max = right;
}
if(max != node){
swap(target_array[max], target_array[node]);
adjust_heap(target_array, max, size);
}
}
void heap_sort(int target_array[], int size){
for(int i = size/2 - 1; i >= 0;i--){
adjust_heap(target_array, i, size);
}
for(int i = size - 1;i>=0 ; i--){
swap(target_array[0], target_array[i]);
adjust_heap(target_array, 0, i);
}
}
int main(){
heap_sort(g_array, sizeof(g_array) /sizeof(g_array[0]);
for(auto item : g_array){
std::cout << item << std::endl;
}
}