The following experiment two selected one.
1, using the queue to achieve the maze algorithm, find the shortest path.
2. Implement all basic operations of sequential queue and chain queue, Initqueue (&q); Destroyqueue (&q); Clearqueue (&q); Queueempty (q); Queuelength (q) ; GetHead (Q, &e); EnQueue (&q, E); DeQueue (&q, &e); Queuetraverse (Q, visit ()).
Lab 1:
1 //2 //by Coolxxx3 //4#include <stdio.h>5#include <stdlib.h>6#include <string.h>7 #defineMax (a) (a) > (b)? ( A):(B))8 #defineMin (a) < (b) ( A):(B))9 #defineABS (a) ((a) >0? ( A):(-(a)))Ten #defineSqr (a) ((a) * (a)) One #defineSwap (a) (a) ^= (b), (b) ^= (a), (a) ^= (b) A #defineEPS 1e-8 - #defineMAX 0x7f7f7f7f - #defineN 1004 the #defineM 1000004 - intN,m,ans,lll,cas,cass; - intSx,sy,ex,ey; - intq[m][2]; + intFa[m]; - intU[n][n]; + CharMap[n][n]; A intdx[]={-1,1,0,0}; at intdy[]={0,0,-1,1}; - voidPrintintx) - { - inti,j; - if(q[x][0]==SX && q[x][1]==Sy) - { inprintf"(%d,%d)", sx,sy); - return; to } + print (fa[x]); -printf"(%d,%d)", q[x][0],q[x][1]); the } * intSPFA () $ {Panax Notoginseng inti,j,x,y,xx,yy,h,t; -memset (Q,0,sizeof(q)); theH=0; t=1; +q[1][0]=sx;q[1][1]=Sy; Au[sx][sy]=1; the while(h!=t) + { -x=q[++h][0];y=q[h][1]; $ if(X==ex && y==ey) $ { - print (fa[t]); -printf"(%d,%d) \ n", Ex,ey); the return 1; - }Wuyi for(i=0;i<4; i++) the { -xx=x+Dx[i]; Wuyy=y+Dy[i]; - if(xx<1|| yy<1|| Xx>n | | Yy>m | | map[xx][yy]=='1'|| U[XX][YY])Continue; Aboutq[++t][0]=xx; $q[t][1]=yy; -fa[t]=h; -u[xx][yy]=1; - } A } + return 0; the } - intMain () $ { the //freopen ("1.txt", "R", stdin); the inti,j; thescanf"%d",&n); them=n;sx=1; sy=1; ex=n;ey=m; - for(i=1; i<=n;i++) in { thescanf"%s", map[i]+1); thePuts (map[i]+1); About } the if(map[sx][sy]=='1'|| map[ex][ey]=='1') {puts ("No");return 0;} the if(!SPFA ()) puts ("No"); the return 0; + } - /* the Bayi */
View Code
Lab 2:
Reference to STL queue
XMU C Language Programming practice (4)