create or replace package plsql_algorithm is
-- Author : cs
-- Created : 2019/9/4 14:27:08
-- Purpose : plsql排序算法
N constant int := 9;
-- 数组类型
type typ_array is table of int index by pls_integer;
--初始化数组
procedure init_array;
procedure init_array_asc;
procedure init_array_desc;
--打印数组
procedure print_array;
--*********************常用排序算法*********************
-- 选择排序
procedure selectionSort;
-- 冒泡排序
procedure bubbleSort;
-- 插入排序
procedure insertSort;
-- 快速排序
procedure quickSort(p int default 1, r int default N);
function Partition(p int, r int) return int;
--归并排序
procedure mergeSort(p int default 1, r int default N);
procedure merge(p int, r int);
end plsql_algorithm;
create or replace package body plsql_algorithm is
-- 私有静态变量-数组长度
--n constant int := 9;
-- 私有变量
array typ_array;
-- 临时数组--归并排序用
array_tmp typ_array;
--初始化数组
procedure init_array is
begin
-- 初始化
array(1) := 8;
array(2) := 1;
array(3) := 2;
array(4) := 7;
array(5) := 4;
array(6) := 6;
array(7) := 3;
array(8) := 9;
array(9) := 5;
end init_array;
procedure init_array_asc is
begin
-- 初始化
array(1) := 1;
array(2) := 2;