sort.h
来自「这是本人精心搜集的关于常用图论算法的一套源码」· C头文件 代码 · 共 28 行
H
28 行
#include "SQList.h"
#include "Key.h"
typedef Key Record;
template <class Record>
class Sortable_list: public List<Record>
{ public:
void insertion_sort( );
private:
};
template <class Record>
void Sortable_list<Record>::insertion_sort( )
{ int first_unsorted; //position of first_unsorted entry
int position; //searches sorted part of list
Record current; //holds the entry temporarily removed from list
for(first_unsorted = 1; first_unsorted < count; first_unsorted++)
if(entry[first_unsorted] < entry[first_unsorted-1])
{ position = first_unsorted;
current = entry[first_unsorted]; // Pull unsorted entry out of the list.
do{ // Shift all entries until the proper position is found.
entry[position] = entry[position-1];
position--; //position is empty.
} while(position>0 && entry[position-1]>current);
entry[position] = current;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?