E.堆排序:
procedure sift(i,m:integer);{调整以i为根的子树成为堆,m为结点总数}
var k:integer;
第1题:
(27)下列函数过程 Function Func(a As Integer,b As Integer)As Integer Static m As Integer,i As Integer M=0 i=2 A=i+m+1 b=i+a+b Func2=m End Function Private Sub Command1_Click() Dim p As Integer,k As Integer,m As Integer k=4 m=1 P=Func2(k,m) Print k;m End Sub程序运行后,单击命令按钮,输出结果是 A.3 6<CR>3 6 B.3 6<CR>3 11C.3 11<CR>3 6 D.3 11<CR>3 11
第2题:
有如下程序: Private Sub Command1_Click() Dim k As Integer,m As Integer Dim p As Integer k=4:m=1 p=PC(k,m):Print p; p=PC(k,m):Print p End Sub Private Function PC(a As Integer,b As Integer) Static m As Integer,i As Integer m=0:i=2 i=i + m + 1 m=i + a + b PC=m End Function 程序运行后,输出的结果为
A.4 6
B.6 6
C.8 8
D.10 12
第3题:
有如下的程序: Private Sub Command1_Click() Dim k As Integer,m As Integer Dim P As Integer k=4:m=1 P=Fun(k,m):Print P; P=Fun(k,m):Print P End Sub Private Function Fun(a As Integer,b As Integer) Static m As Integer,i As Integer in=5:i=2 i=i+m+1 m=i+a+b Fun=m\2 End Function 单击命令按钮后,输出结果为
A.2 2
B.4 4
C.5 5
D.6 6
第4题:
有如下的程序。
Private Sub Command1_Click()
Dim k As Integer, m As Integer
Dim P As Integer
k=4: m=1
P=Fun(k, m) : Print P;
P=Fun(k, m) : Print P
End Sub
Private Function Fun(a As Integer, b As Integer)
Static m As Integer, i As Integer
m=5: i=2
i=i + m + 1
m=i + a + b
Fun=m \ 2
End Function
单击命令按钮后,输出结果为
A.2 2
B.4 4
C.5 5
D.6 6
第5题:
C.选择排序:
procedure sort;
var i,j,k:integer;
begin
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then swap(a[i],a[j]);
end;
第6题:
高精度数的定义:
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}
第7题:
高精度乘以低精度
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 (len>1) and (c[len]=0) do dec(len); {若不需进位则调整len}
c[0]:=len;
end;{multiply}
第8题:
已知前序中序求后序
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;
第9题:
单链表的插入操作
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;
第10题:
有如下的函数过程: Function Func2(a As Integer, b As Integer)'As Integer Static m As Integer, i As Integer m=0 i=2 a=i+m+1 b=i+a+b Func2=m End Function 在窗体上画一个命令按钮,然后编写如下事件过程: Private Sub Command1_Click() Dim p As Integer, k As Integer, m As Integer k=4 m=1 p=Fune2(k, m) Print k; m p = Func2(k, m) Print k; m End Sub 程序运行后,单击命令按钮,输出结果为( )。
A.3 6<CR>3 6
B.3 6<CR>3 11
C.3 11<CR>3 6
D.3 11<CR>3 11
第11题:
在窗体上画一个按钮,然后编写如下的事件代码。在按钮上单击,输出为( )。 Private Function fun(x As Integer,y As Integer) Static m As Integer Static i As Integer i=i+2 i=i+m+1 m=i+x+y fun=m End Function Private Sub Command1_Click() Dim j As Integer,m As Integer,k As Integer j=4:m=1 k=fun(j,m) Print k; k=fun (j,m) Print k End Sub
A.8 18
B.7 17
C.7 19
D.8 19
第12题:
下列程序段的执行结果为 ______。 Dim m(3,3)As Integer Dim i As Integer Dim j As Integer Dim K As Integer For i=1 To 3 m(i,i)=i Next For i=0 To 3 For j=0 To 3 x=x+m(i,j) Next Next Print x
A.3
B.4
C.5
D.6
第13题:
有如下的程序:
Private Sub Command1_Click()
Dim k As Integer,m AB Integer
Dim P As Integer
k=4:m=1
P=Fun(k,m) =Print P;
P=Fun(k,m) :Print P
End Sub
Private Function Fun(a As Integer,b As Integer)
Static m As Integer,i As Integer
m=5:i=2
i=i+m+1
m=i+a+b
Fun=m\2
End Function
单击命令按钮后,输出结果为
A. 2 2
B.4 4
C.5 5
D.6 6
第14题:
有如下程序: Private Sub Command1_Click() Dim k As Integer,m As Integer Dim op As Integer k=4:m=1 p=PPC(k,m):Print op; p=PPC(k.m):Print op End Sub Private Function PPC(a As Integer,b As Integer) Static m As Integer,i As Integer m=0:i=2 i=i+m+1 m=i+a+b PPC=m End Function 程序运行后,输出的结果为
A.4 6
B.6 6
C.8 8
D.10 12
第15题:
以下用户自定义函数 Function Func(a As Integer, b As Integer) As Integer Static m As Integer, i As Integer m=0:i=2 i=i+m+i m=i+a+b Func=m End Function 在窗体上画一个命令按钮,然后编写如下事件过程: Private Sub Command1_Click() Dim k As Integer,m As Integer,p As Integer k=4:m=1 P=Func(k,m) Print p End Sub 程序运行后,单击命令按钮,输出结果为
A.8
B.9
C.10
D.11
第16题:
四、排序算法
A.快速排序:
procedure qsort(l,r:integer);
var i,j,mid:integer;
begin
i:=l;j:=r; mid:=a[(l+r) div 2]; {将当前序列在中间位置的数定义为中间数}
repeat
while a[i]<mid do inc(i); {在左半部分寻找比中间数大的数}
while a[j]>mid do dec(j);{在右半部分寻找比中间数小的数}
if i<=j then begin {若找到一组与排序目标不一致的数对则交换它们}
swap(a[i],a[j]);
inc(i);dec(j); {继续找}
end;
until i>j;
if l<j then qsort(l,j); {若未到两个数的边界,则递归搜索左右区间}
if i<r then qsort(i,r);
end;{sort}
第17题:
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]<a[j-1] then swap( a[j],a[j-1]); {每次比较相邻元素的关系}
end;
第18题:
高精度减法
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 (len>1) and (c[len]=0) do dec(len);
c[0]:=len;
end;
第19题:
高精度乘以高精度
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 (len>1) and (c[len]=0) do dec(len);
c[0]:=len;
end;
第20题:
链表的定位函数
loc(I:integer):pointer; {寻找链表中的第I个结点的指针}
procedure loc(L:linklist; I:integer):pointer;
var p:pointer;
j:integer;
begin
p:=L.head; j:=0;
if (I>=1) and (I<=L.len) then
while j<I do begin p:=p^.next; inc(j); end;
loc:=p;
end;
第21题:
单链表的删除操作
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;
第22题:
有如下程序:Private Sub Command1_Click() Dim k As Integer,m As Integer Dim op As Integer k=4:m=1 op:PPC(k,m):Print op; op:PPC(k,m):Print opEnd SubPrivate Function,PPC(a As Integer,b As Integer) Static m As Integer,i As Integer m=0:i=2 i=i+m+1 m=i+a+b PPC=mEnd Function程序运行后,输出的结果为
A.4 6
B.6 6
C.8 8
D.10 12
第23题:
下列程序段的执行结果为______。 Dim m(3,3)As Integer Dim i As Integer Dim j As Integer Dim x As Integer For i=1 To 3 m(i,i)=i Next For i=0 T0 3 For j=0 To 3 x=x+m(i, j) Next Next Print x
A.3
B.4
C.5
D.6