包含c語言中dispose的詞條

本文目錄一覽:

c語言結構體問題,求指教

struct student {

int num;

char name[10];

float scores[3];

float course_aver;

float sum;

float stu_aver;

} stu_date[N], course_date[M];

將結構體的定義放到define下面,否則會出現不完整結構類型

C語言程序中常用的語句…要比較全一點的

B.插入排序:

思路:當前a[1]..a[i-1]已排好序了,現要插入a[i]使a[1]..a[i]有序。

procedure insert_sort;

var i,j:integer;

begin

for i:=2 to n do begin

a[0]:=a[i];

j:=i-1;

while a[0]a[j] then swap(a[i],a[j]);

end;

D. 冒泡排序

procedure bubble_sort;

var i,j,k:integer;

begin

for i:=1 to n-1 do

for j:=n downto i+1 do

if a[j]r) or (a[i]=a[j])) {滿足取左邊序列當前元素的要求}

then begin

tmp[t]:=a[i]; inc(i);

end

else begin

tmp[t]:=a[j];inc(j);

end;

inc(t);

end;

for i:=p to r do a[i]:=tmp[i];

end;{merge}

procedure merge_sort(var a:listtype; p,r: integer); {合併排序a[p..r]}

var q:integer;

begin

if pr then begin

q:=(p+r-1) div 2;

merge_sort (a,p,q);

merge_sort (a,q+1,r);

merge (a,p,q,r);

end;

end;

{main}

begin

merge_sort(a,1,n);

end.

G.基數排序

思想:對每個元素按從低位到高位對每一位進行一次排序

五、高精度計算

高精度數的定義:

type

hp=array[1..maxlen] of integer;

1.高精度加法

procedure plus ( a,b:hp; var c:hp);

var i,len:integer;

begin

fillchar(c,sizeof(c),0);

if a[0]b[0] then len:=a[0] else len:=b[0];

for i:=1 to len do begin

inc(c[i],a[i]+b[i]);

if c[i]10 then begin dec(c[i],10); inc(c[i+1]); end; {進位}

end;

if c[len+1]0 then inc(len);

c[0]:=len;

end;{plus}

2.高精度減法

procedure substract(a,b:hp;var c:hp);

var i,len:integer;

begin

fillchar(c,sizeof(c),0);

if a[0]b[0] then len:=a[0] else len:=b[0];

for i:=1 to len do begin

inc(c[i],a[i]-b[i]);

if c[i]0 then begin inc(c[i],10);dec(c[i+1]); end;

while (len1) and (c[len]=0) do dec(len);

c[0]:=len;

end;

3.高精度乘以低精度

procedure multiply(a:hp;b:longint;var c:hp);

var i,len:integer;

begin

fillchar(c,sizeof(c),0);

len:=a[0];

for i:=1 to len do begin

inc(c[i],a[i]*b);

inc(c[i+1],(a[i]*b) div 10);

c[i]:=c[i] mod 10;

end;

inc(len);

while (c[len]=10) do begin {處理最高位的進位}

c[len+1]:=c[len] div 10;

c[len]:=c[len] mod 10;

inc(len);

end;

while (len1) and (c[len]=0) do dec(len); {若不需進位則調整len}

c[0]:=len;

end;{multiply}

4.高精度乘以高精度

procedure high_multiply(a,b:hp; var c:hp}

var i,j,len:integer;

begin

fillchar(c,sizeof(c),0);

for i:=1 to a[0] do

for j:=1 to b[0] do begin

inc(c[i+j-1],a[i]*b[j]);

inc(c[i+j],c[i+j-1] div 10);

c[i+j-1]:=c[i+j-1] mod 10;

end;

len:=a[0]+b[0]+1;

while (len1) and (c[len]=0) do dec(len);

c[0]:=len;

end;

5.高精度除以低精度

procedure devide(a:hp;b:longint; var c:hp; var d:longint);

{c:=a div b; d:= a mod b}

var i,len:integer;

begin

fillchar(c,sizeof(c),0);

len:=a[0]; d:=0;

for i:=len downto 1 do begin

d:=d*10+a[i];

c[i]:=d div b;

d:=d mod b;

end;

while (len1) and (c[len]=0) then dec(len);

c[0]:=len;

end;

6.高精度除以高精度

procedure high_devide(a,b:hp; var c,d:hp);

var

i,len:integer;

begin

fillchar(c,sizeof(c),0);

fillchar(d,sizeof(d),0);

len:=a[0];d[0]:=1;

for i:=len downto 1 do begin

multiply(d,10,d);

d[1]:=a[i];

while(compare(d,b)=0) do {即d=b}

begin

Subtract(d,b,d);

inc(c[i]);

end;

end;

while(len1)and(c.s[len]=0) do dec(len);

c.len:=len;

end;

六、 樹的遍歷

1.已知前序中序求後序

procedure Solve(pre,mid:string);

var i:integer;

begin

if (pre=””) or (mid=””) then exit;

i:=pos(pre[1],mid);

solve(copy(pre,2,i),copy(mid,1,i-1));

solve(copy(pre,i+1,length(pre)-i),copy(mid,i+1,length(mid)-i));

post:=post+pre[1]; {加上根,遞歸結束後post即為後序遍歷}

end;

2.已知中序後序求前序

procedure Solve(mid,post:string);

var i:integer;

begin

if (mid=””) or (post=””) then exit;

i:=pos(post[length(post)],mid);

pre:=pre+post[length(post)]; {加上根,遞歸結束後pre即為前序遍歷}

solve(copy(mid,1,I-1),copy(post,1,I-1));

solve(copy(mid,I+1,length(mid)-I),copy(post,I,length(post)-i));

end;

3.已知前序後序求中序的一種

function ok(s1,s2:string):boolean;

var i,l:integer; p:boolean;

begin

ok:=true;

l:=length(s1);

for i:=1 to l do begin

p:=false;

for j:=1 to l do

if s1[i]=s2[j] then p:=true;

if not p then begin ok:=false;exit;end;

end;

end;

procedure solve(pre,post:string);

var i:integer;

begin

if (pre=””) or (post=””) then exit;

i:=0;

repeat

inc(i);

until ok(copy(pre,2,i),copy(post,1,i));

solve(copy(pre,2,i),copy(post,1,i));

midstr:=midstr+pre[1];

solve(copy(pre,i+2,length(pre)-i-1),copy(post,i+1,length(post)-i-1));

end;

七 進制轉換

1.任意正整數進制間的互化

除n取余

2.實數任意正整數進制間的互化

乘n取整

3.負數進制:

設計一個程序,讀入一個十進制數的基數和一個負進制數的基數,並將此十進制數轉換為此負進制下的數:-R∈{-2,-3,-4,….-20}

八 全排列與組合的生成

1.排列的生成:(1..n)

procedure solve(dep:integer);

var

i:integer;

begin

if dep=n+1 then begin writeln(s);exit; end;

for i:=1 to n do

if not used[i] then begin

s:=s+chr(i+ord(”0”));used[i]:=true;

solve(dep+1);

s:=copy(s,1,length(s)-1); used[i]:=false;

end;

end;

2.組合的生成(1..n中選取k個數的所有方案)

procedure solve(dep,pre:integer);

var

i:integer;

begin

if dep=k+1 then begin writeln(s);exit; end;

for i:=1 to n do

if (not used[i]) and (ipre) then begin

s:=s+chr(i+ord(”0”));used[i]:=true;

solve(dep+1,i);

s:=copy(s,1,length(s)-1); used[i]:=false;

end;

end;

九.查找算法

1.折半查找

function binsearch(k:keytype):integer;

var low,hig,mid:integer;

begin

low:=1;hig:=n;

mid:=(low+hig) div 2;

while (a[mid].keyk) and (low=hig) do begin

if a[mid].keyk then hig:=mid-1

else low:=mid+1;

mid:=(low+hig) div 2;

end;

if lowhig then mid:=0;

binsearch:=mid;

end;

2.樹形查找

二叉排序樹:每個結點的值都大於其左子樹任一結點的值而小於其右子樹任一結點的值。

查找

function treesrh(k:keytype):pointer;

var q:pointer;

begin

q:=root;

while (qnil) and (q^.keyk) do

if kgoal then begin {若未移到目標}

Move(k-1,6-now-goal); {剩下的先移到沒用的柱上}

Writeln(k moved from now to goal);

H[goal,h[goal,0]+1]:=h[now,nowp]; h[now,nowp]:=0;

Inc(h[goal,0]); dec(h[now,0]);

Move(k-1,goal); {剩下的移到目標上}

End;

十二、DFS框架

NOIP2001 數的劃分

procedure work(dep,pre,s:longint); {入口為work(1,1,n)}

{dep為當前試放的第dep個數,pre為前一次試放的數,s為當前剩餘可分的總數}

var j:longint;

begin

if dep=n then begin

if s=pre then inc(r); exit;

end;

for j:=pre to s div 2 do work(dep+1,j,s-j);

end;

類似:

procedure try(dep:integer);

var i:integer;

begin

if dep=k then begin

if tot=a[dep-1] then inc(sum);

exit; end;

for i:=a[dep-1] to tot div 2 do begin

a[dep]:=i; dec(tot,i);

try(dep+1);

inc(tot,i);

end;

end;{try}

十三、BFS框架

IOI94 房間問題

head:=1; tail:=0;

while tail=1) and (I=L.len) then

while jI do begin p:=p^.next; inc(j); end;

loc:=p;

end;

2.單鏈表的插入操作

procedure insert(L:linklist; I:integer; x:datatype);

var p,q:pointer;

begin

p:=loc(L,I);

new(q);

q^.data:=x;

q^.next:=p^.next;

p^.next:=q;

inc(L.len);

end;

3.單鏈表的刪除操作

procedure delete(L:linklist; I:integer);

var p,q:pointer;

begin

p:=loc(L,I-1);

q:=p^.next;

p^.next:=q^.next;

dispose(q);

dec(L.len);

end;

4.雙鏈表的插入操作(插入新結點q)

p:=loc(L,I);

new(q);

q^.data:=x;

q^.pre:=p;

q^.next:=p^.next;

p^.next:=q;

q^.next^.pre:=q;

5.雙鏈表的刪除操作

p:=loc(L,I); {p為要刪除的結點}

p^.pre^.next:=p^.next;

p^.next^.pre:=p^.pre;

dispose(p);

在c語言函數的遞歸調用中x=fib(i)是什麼意思

遞歸就是在過程或函數里調用自身。在使用遞歸策略時,必須有一個明確的遞歸結束條件,稱為遞歸出口。

int rev(int i)

{

if(i5) rev(i++);

else return i;

}

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/194346.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-02 14:38
下一篇 2024-12-02 14:38

相關推薦

  • AES加密解密算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演着非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • OpenJudge答案1.6的C語言實現

    本文將從多個方面詳細闡述OpenJudge答案1.6在C語言中的實現方法,幫助初學者更好地學習和理解。 一、需求概述 OpenJudge答案1.6的要求是,輸入兩個整數a和b,輸出…

    編程 2025-04-29
  • Python按位運算符和C語言

    本文將從多個方面詳細闡述Python按位運算符和C語言的相關內容,並給出相應的代碼示例。 一、概述 Python是一種動態的、面向對象的編程語言,其按位運算符是用於按位操作的運算符…

    編程 2025-04-29
  • Python語言由荷蘭人為中心的全能編程開發工程師

    Python語言是一種高級語言,很多編程開發工程師都喜歡使用Python語言進行開發。Python語言的創始人是荷蘭人Guido van Rossum,他在1989年聖誕節期間開始…

    編程 2025-04-28
  • Python語言設計基礎第2版PDF

    Python語言設計基礎第2版PDF是一本介紹Python編程語言的經典教材。本篇文章將從多個方面對該教材進行詳細的闡述和介紹。 一、基礎知識 本教材中介紹了Python編程語言的…

    編程 2025-04-28
  • Python語言實現人名最多數統計

    本文將從幾個方面詳細介紹Python語言實現人名最多數統計的方法和應用。 一、Python實現人名最多數統計的基礎 1、首先,我們需要了解Python語言的一些基礎知識,如列表、字…

    編程 2025-04-28
  • Python作為中心語言,在編程中取代C語言的優勢和挑戰

    Python一直以其簡單易懂的語法和高效的編碼環境而著名。然而,它最近的發展趨勢表明Python的使用範圍已經從腳本語言擴展到了從Web應用到機器學習等廣泛的開發領域。與此同時,C…

    編程 2025-04-28
  • Python基礎語言

    Python作為一種高級編程語言擁有簡潔優雅的語法。在本文中,我們將從多個方面探究Python基礎語言的特點以及使用技巧。 一、數據類型 Python基礎數據類型包括整數、浮點數、…

    編程 2025-04-28

發表回復

登錄後才能評論