DECLARE
TYPE seq_st_tt IS TABLE OF INT;
seq_st seq_st_tt := seq_st_tt(20,-10,-5,-3,5,4,-2,7,40);
tmpsum INT := 0;
maxval INT :=seq_st(1);
spos INT := 1;
epos INT := 1;
nspos INT := 1;
nepos INT := 1;
BEGIN
FOR i IN 1..seq_st.count LOOP
tmpsum := tmpsum + seq_st(i);
IF(tmpsum < 0) THEN
nspos := i + 1;
nepos := i + 1;
tmpsum := 0;
ELSIF(tmpsum >= maxval) THEN
spos := nspos;
epos := nepos;
nepos := nepos + 1;
maxval := tmpsum;
ELSE
nepos := nepos + 1;
END IF;
END LOOP;
dbms_output.put_line('the max linear sequence from '||spos||' to '||epos||' is '||maxval);
END;
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。