oracleheap_sort
CREATE OR REPLACE PACKAGE heap_sort_pkg
创新互联公司主要业务有网站营销策划、网站建设、网站设计、微信公众号开发、小程序制作、H5技术、程序开发等业务。一次合作终身朋友,是我们奉行的宗旨;我们不仅仅把客户当客户,还把客户视为我们的合作伙伴,在开展业务的过程中,公司还积累了丰富的行业经验、网络营销推广资源和合作伙伴关系资源,并逐渐建立起规范的客户服务和保障体系。
AS
TYPE num_arr_tt IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER;
PROCEDURE add_nums(num_arr_inst IN OUT num_arr_tt, dvalue INT);
PROCEDURE del_nums(num_arr_inst IN OUT num_arr_tt);
FUNCTION get_maxval(num_arr_int IN OUT num_arr_tt) RETURN INT;
END heap_sort_pkg;
CREATE OR REPLACE PACKAGE BODY heap_sort_pkg
AS
PROCEDURE add_nums(num_arr_inst IN OUT num_arr_tt, dvalue INT)
AS
dest_loc INT := num_arr_inst.count + 1;
tmp_loc INT := trunc(dest_loc / 2);
BEGIN
WHILE(tmp_loc > 0 AND dvalue > num_arr_inst(tmp_loc)) LOOP
num_arr_inst(dest_loc) := num_arr_inst(tmp_loc);
dest_loc := tmp_loc;
tmp_loc := trunc(dest_loc / 2);
END LOOP;
num_arr_inst(dest_loc) := dvalue;
END add_nums;
PROCEDURE del_nums(num_arr_inst IN OUT num_arr_tt)
AS
lvalue INT;
rvalue INT;
umark INT := 1;
tmark INT := umark;
tvalue INT := num_arr_inst(num_arr_inst.count);
BEGIN
IF(num_arr_inst.count <= 1) THEN
num_arr_inst.delete(1);
dbms_output.put_line('只有一个值或无值');
RETURN;
END IF;
num_arr_inst.delete(num_arr_inst.count);
lvalue := umark * 2;
rvalue := umark * 2 + 1;
WHILE(umark <= num_arr_inst.count/2) LOOP
IF(num_arr_inst.exists(lvalue) AND num_arr_inst.exists(rvalue) AND num_arr_inst(lvalue) < num_arr_inst(rvalue)) THEN
tmark := rvalue;
ELSE
tmark := lvalue;
END IF;
IF(tvalue < num_arr_inst(tmark)) THEN
num_arr_inst(umark) := num_arr_inst(tmark);
ELSE
EXIT;
END IF;
umark := tmark;
lvalue := umark * 2;
rvalue := umark * 2 + 1;
END LOOP;
num_arr_inst(umark) := tvalue;
END del_nums;
FUNCTION get_maxval(num_arr_int IN OUT num_arr_tt) RETURN INT
AS
max_value INT := -1;
BEGIN
IF(num_arr_int.exists(1)) THEN
max_value := num_arr_int(1);
del_nums(num_arr_int);
END IF;
RETURN max_value;
END get_maxval;
END heap_sort_pkg;
网站栏目:oracleheap_sort
新闻来源:http://hbruida.cn/article/jhdgpi.html