倍。 (2)根據(jù)上述掃描算法,其 VB 代碼實(shí)現(xiàn)如下,請(qǐng)?jiān)跈M線(xiàn)處填入合適的代碼。 Dim a(0 To 1000)As Integer'存儲(chǔ)原矩陣數(shù)據(jù),按行優(yōu)先存儲(chǔ) Dim b(0 To 1000)As Integer'存儲(chǔ)Z形掃描后數(shù)據(jù) Dim c(0 To 1000)As Integer'存儲(chǔ)行程編碼壓縮后數(shù)據(jù) Dim n As Integer ‘矩陣導(dǎo)入代碼略,以行優(yōu)先存儲(chǔ)在a數(shù)組中,如例子中數(shù)據(jù)存儲(chǔ)順序?yàn)椤?7,45,0,23,0,0…” Private Sub Command2_Click ( ) Dim choice As Integer'1:向右移動(dòng);2:向右上移動(dòng);3向下移動(dòng) 4向左下移動(dòng) Dim row As Integer,col As Integer,i As Integer,j As Integer Dim pre As Integer,count As Integer choice=1:row=0:col=0:i=0 Do While (row<>n-1 Or col<>n-1) b(i)=a(row*n+col):i=i+1 If choice=1 Then
col=col+1
col=col+1
If row=0 Then choice=4 Else choice=2 ElseIf choice=2 Then row=row-1:col=col+1 If
row=0 And col<>n-1
row=0 And col<>n-1
Then choice=1 ElseIf col=n-1 Then choice=3 End If ElseIf choice=3 Then row=row+1 If col=0 Then choice=2 Else choice=4 ElseIf choice=4 Then row=row+1:col=col-1 If row=n-1 Then choice=1 ElseIf col=0 Then choice=3 End If End If Loop b(i)=a(n*n-1):j=0:pre=b(0):count=0 For i=0 To n*n-1'輸出Z形序列,并進(jìn)行行程壓縮 If pre=b(i)Then count=count+1 Else c(j)=pre:c(j+1)=count
count=1
count=1
pre=b(i):j=j+2 End If Next i c(j)=pre:c(j+1)=count Text1.Text=““ For i=0 To j+1 Text1.Text=Text1.Text+Str(c(i))+“,“ Next i End Sub