遞迴的一些應用

2021-09-29 03:52:16 字數 894 閱讀 8315

遞迴:簡單來說就是自己呼叫自己。

下面用乙個簡單的例子說明遞迴的主要步驟

#include

void

up_and_down

(int);

intmain

(void

)void

up_and_down

(int n)

printf

("level %d: n location %p\n"

,n,&n)

;}

level 1

: n location 000000000061fe00

level 2

: n location 000000000061fdd0

level 3

: n location 000000000061fda0

level 4

: n location 000000000061fd70

level 4

: n location 000000000061fd70

level 3

: n location 000000000061fda0

level 2

: n location 000000000061fdd0

level 1

: n location 000000000061fe00

每乙個函式呼叫都有自己的變數

每次函式呼叫都會返回一次

遞迴函式位於遞迴呼叫之前的語句,均按被調函式的順序執行遞迴函式中位於遞迴呼叫之後的語句,均按被調函式相反的順序執行雖然每級遞迴都有自己的變數,但是並沒有拷貝函式的**。

pta 習題 2.6

遞迴的一些經典應用

今天看了一些關於遞迴的知識,順便學習了一些經典的問題,敲了一些小 首先是遞迴實現的經典的二分問題,如下 include include using namespace std int a 10 int binsearch int left,int right,int goal int main re...

sed的一些應用

sed 在滲透的時候很有作用 具體如下 以下命令將a.txt文字中的所有的 127.0.0.1 替換為 192.168.0.8 sed i s 127.0.0.1 192.168.0.8 g a.txt 如果不想改動原檔案a.txt,則可以用以下命令生成新檔案new.txt sed e s 127....

正則的一些應用

根據正則提取字串資訊的方法 public static string regexpextract string str,string regex pattern regex pattern pattern.compile regex matcher matcher regex pattern.mat...