This presentation is the property of its rightful owner.
Sponsored Links
1 / 50

第五章 多维数组与广义表 PowerPoint PPT Presentation


  • 111 Views
  • Uploaded on
  • Presentation posted in: General

第五章 多维数组与广义表. 2007.9. 5.1 多维数组 5.1.1 多维数组的定义 5.1.2 多维数组的存储 5.2 矩阵的压缩存储 5.2.1 特殊矩阵 5.2.2 稀疏矩阵 5.3 广义表. 5.1 多维数组. 5.1.1 多维数组的定义. 一维数组 一维数组可以看成是一个线性表或一个向量,它在计算机内是存放在一块连续的存储单元中,适合于随机查找。 有一个直接前驱和一个直接后继 二维数组 二维数组可以看成是向量的推广。 有两个直接前驱和两个直接后继. 三维数组 最多可有三个直接前驱和三个直接后继 多维数组

Download Presentation

第五章 多维数组与广义表

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


3999787

2007.9


3999787

  • 5.1

    5.1.1

    5.1.2

  • 5.2

    5.2.1

    5.2.2

  • 5.3


3999787

5.1


5 1 1

5.1.1


3999787


3999787

C

typedef int datatype;

datatype array1[N];

datatype array2[M][N];

datatype array3[X][Y][Z];


3999787

5.2


3999787

    • PASCALC

    • FORTRAN


3999787


3999787

a

a

a

a

a

a

00

00

01

01

0n

0n

-

-

1

1

a

a

a

a

a

a

10

10

11

11

1n

1n

-

-

1

1

.

.

a

a

a

a

a

a

m

m

-

-

1 0

1 0

m

m

-

-

1 1

1 1

m

m

-

-

1 n

1 n

-

-

1

1

0

ListSize -1


3999787

  • 1,,d

  • Amn aij

    LOC(aij)=LOC(a11)+[(i-1)*n+j-1]*d

  • Amnpaijk

    LOC(aijk)=LOC(a111)+[(i-1)*n*p+(j-1)*p +(k-1)]*d


3999787

  • A[c1..d1,c2..d2]c1,c21

    aij

    LOC(aij)=LOC(ac1c2)+[(i-c1)*(d2-c2+1)+j-c2)]*d

  • C0C

    LOC(aij)=LOC(a00)+(i*(d2+1)+j)*d


3999787

Ai1in

=


3999787


2006 1

2006-1

  • a[04,15]1a[2,1]___(40)___(40)A5B10

    C15D25

2003

  • a[3..165..20]a[i,j](3i165j20)___(11)___

    (11)Aa-118+2i+28jBa-116+2i+28j

    Ca-144+2i+28jDa-146+2i+28j


3999787

2001

  • X 05,18,,__(6)__,X 382,X ()__(7)__,Xd,X{1,5] __(8)__, __(9)__,X[4,8]__(10)__

  • (6): A.210 B.240 C.288 D.294

  • (7): A.0 B.6 C.94 D.100

  • (8): A.Xd+24 B.Xd+72 C.Xd+78 D.Xd+144

  • (9): A.Xd+29 B.Xd+77 C.Xd+83 D.Xd+147

  • (10):A.Xd+186 B.Xd+234 C.Xd+270 D.Xd+276


3999787

5.2


3999787


5 2 1

5.2.1

nAaij=aji 0i,jn-1A


3999787

    • ()()

    • c


3999787


3999787


5 2 2

5.2.2

    • C0


3999787

=

Aij

=


3999787

1.

  • Aij


3999787

2.

  • Aij


3999787

3.

  • Aij

Aiji,3*i-1,

i aijj-i+1

3*i-1+(j-i+1) = 2*i+j


3999787

2004-1 __(5)__

(5) AB

CD

2003 A[l..1001..100]B[l..298]AA[66,65]B___(4)___

(4) A195 B196C197D198


5 2 3

5.2.3


3999787

1.

    • (i,j,aij)

    • MNT

M=5

N=5

T=7


3999787

C

#define maxsize 10000

typedef int datatype;

typedef struct{/**/

int i,j;

datatype v;

}TriTupleNode;

typedef struct{

TriTupleNode data[maxsize]; /**/

int m,n,t;/*,,*/

}TriTupleTable;


3999787

2


3999787

3.


5 2 4

5.2.4

1.

mnABnma[i][j]=b[j][i]0im0jn

Aij=Bji


3999787

2.

Aij=Bji

M=4

N=2

T=5

M=2

N=4

T=5


A data i j

a.dataij

b.dataB

B

Aij=Bji

M=2

N=4

T=5

i

M=4

N=2

T=5


3999787

M=2

N=4

T=5

b.m=a.n; b.n=a.m; b.t=a.t;/**/

/*ijB*/

for ( i=0; i<b.t; i++ ) { b.data[i].i=a.data[i].j; b.data[i].j=a.data[i].i; b.data[i].v=a.data[i].v;}

/*Bi*/

M=4

N=2

T=5

i


3999787

AB

  • BA

  • Acol a.datacolb.dataB

Aij=Bji

col=0

col=1234

col=256

M=4

N=2

T=5

M=2

N=4

T=5


3999787

Void transmatrix(tripletable a,tripletable b)

{ int pa, pb, col;

b.m=a.n; b.n=a.m; b.t=a.t; /**/

if(b.t<=0) { printf(A=0\n); return 0;} /**/

pb=0; /*pbB*/

for(col=0;col<a.n;col++)/*colA*/

for(pa=0;pa<=a.t;pa++) /*pbA*/

/*coli,jB*/

if(a.data[pa].j==col){ b.data[pb].i=a.data[pa].j;

b.data[pb].j=a.data[pa].i;

b.data[pb].v=a.data[pa].v;

pb++;

}

}


3999787

  • pacolO(n*t)

  • O(n*m)

  • tm*nO(m*n2)

  • t<=m*n


3999787

  • ABB.

  • B

    • AB=

      B

      +


3999787

M=2

N=4

T=5

M=4

N=2

T=5

Aij=Bji

cpos

cpos[0]=0

cpos[i]=cpos[i-1]+cnum[i-1]


3999787

void fasttranstri(tritupletable b,tritupletable a)

{ intcol/**/

int pa, pb; /*pa,pb:a,b*/

int cnum[0..a.n], cpos[0..a.n];

bm,n,t

a

cnum

/*a*/

for(pa=0; pa<a.t; pa++) { col=a.data[pa].j; cnum[col]++;}

/*cpos*/

cpos[0]=0;

for(col=1;col<=a.n;col++)

cpos[col] = cpos[col-1] + cnum[col-1];


3999787

/*ai,jb*/

for( pa=0; pa<a.t; pa++ ){

col = a.data[p].j;

pb = cpot[col];

b.data[pb].i = a.data[pa].j;

b.data[pb].j = a.data[pa].i;

b.data[pb].v = a.data[pa].v;

cpos[col]++;

}

}

}


3999787

  • On+t

  • tm*nO(m*n)


3999787

5.3


3999787

5.5.1

2

1

n0a1a2anaiLS=(a1,a2,,an)LSn ai

2

1A=( )A0

2B=(a,b,c)B2

3C=(x,y,z)C3

4D=(B,C)D2

5E=(a,E)2


3999787

3

1LS=(a1a2an)ai

A=(b,c), B=(a,A) , E=(a,E)

2

ABC

A(b,c)

B(a,A(b,c))

E(a,E(a,E))

3


3999787

4

.

1A=(b,c) 2B=(a,A) 3C=(A,B) (4) E=(a,E)

depth=1 depth=2 depth=3 depth=

E

a

5

1

2 (1)(2)

3() (3)

4(4)


  • Login