1、data.val=b; /输入密码data.num=j; /输入序号next=head- /将尾结点的next域指向第一个结点,构成循环链表请输入一个数m:m); if(m /p指向输出结点next=p- /将输出结点的前结点的next域指向输出结点的后结点num:%dtval:%dn,p-data.num,p-data.val); /输出 m=p-data.val; /取得输出结点的密码 free(p); while(q-next!=q); /只剩最后一个结点时结束,q-data.num,q- /输出最后一个结点 free(q); /释放最后一个结点 free(head); /释放头结点 s
2、ystem(pause第3章(1)iostreamconio.h#define M 4#define N 6#define MaxSize 100using namespace std;int mgM+2N+2= 1,1,1,1,1,1,1,1, 1,0,0,1,0,0,0,1, 1,1,0,0,0,0,0,1, 1,0,0,1,0,1,0,1, 1,0,0,0,0,0,0,1,;struct int i,j,di;StackMaxSize,PathMaxSize;int top=-1;int count=1;int minlen=MaxSize;void Print() for(int i
3、= 0;i M+2;i+) for(int j = 0;j N+2;j+) if(mgij) cout1 ; else cout0 cout-1) i=Stacktop.i; j=Stacktop.j; di=Stacktop.di; if(i=M&j=N) coutcount+ for(k=0;k=top;k+)(Stackk.i,Stackk.j) if(k+1)%5=0)cout if(top+1minlen) Pathk=Stackk; minlen=top+1; mgStacktop.iStacktop.j=0; top-; find=0; while(di4&find=0) di+
4、; switch(di) case 1:i=Stacktop.i;j=Stacktop.j+1;break; case 2:i=Stacktop.i+1;j=Stacktop.j; if(mgij=0) find=1; if(find=1) Stacktop.di=di; Stacktop.i=i; Stacktop.j=j; mgij=-1; else最短路径如下:长度:minlen路径:minlen;Pathk.iPathk.j if(k+1)%5=0) cout#include time.h#define LEN sizeof(STACK) typedef struct node int
5、 data; struct node *link;STACK50,*STLink;STLink top50; void init(STLink top,int m) /*初始化堆栈*/ topm=NULL; int empty( STLink top,int n) /*判断是否为空*/ return (topn=NULL); int push(STLink top,int A,int m) /*入栈*/ STLink p; if(!(p=(STLink)malloc(LEN) return 0; p-data=A;link=topm; topm=p; return 1; int pop(STL
6、ink top,int m) /*出栈*/ int A; p=topm; A=p-data; topm=topm-link; return A; int trainpush(int M,int A,STLink top) int m,k=0,l; topk=NULL; /* 初始化第一个堆栈 */ push(top,A0,0); /*把第一节车厢压入缓冲铁轨*/缓冲铁轨: 1 栈顶值:,top0-data); for(m=1;mtopk-data) /*前面所有栈顶值最大值一定为最后一个栈的栈顶值,如果此次需 进栈的车厢号比前面所有栈顶值都大重新建立一个新的栈并把车厢号压入新的栈的栈底*/in
7、it(top,+k); push(top,Am,k);printf(缓冲铁轨:%d 栈顶值:,k+1,topk-else /* 将此次需进栈的车厢号与所有栈顶值比较,插入到第一次遇到的栈顶值比将要入栈的车厢号要大的栈中,比如要插入10号车厢,缓冲铁轨的栈顶值排列如下:2、11、5、12,13,将10插在11所在的栈的栈顶*/ l=0;while(ldata)l+;push(top,Am,l); %d 栈顶值:,l+1,topl-l=k+1; return k+1;void trainpop(int M,int A,STLink top,int N) int m,n=0,min,l=0,amin
8、=0,bmin=0; /*把所有车厢都压出缓冲铁轨*/ min=topn-for(m=0;m+) for(l=n+1;ldata amin=l; /*将栈顶值最小的栈的栈号保存起来*/ Am=pop(top,amin); /*把最小的栈顶元素压出栈并赋值给A*/A%d=%dn,m,Am); if(topamin=NULL) min=topamin+1- n=amin+1; min=topamin- n=amin; int main(void)int i,M,A100,N=0;请输入火车车厢总长:M);请输入未转轨前车厢的排列顺序,不能输入重复相同数据且不可遗漏车厢号nfor(i=0;iscan
9、f(Ai); for(i=0;,i,Ai); N=trainpush(M,A,top);所使用的缓冲铁轨数为:,N);火车转轨后,出轨顺序如下,请核对是否是所需顺序: trainpop(M,A,top,N);第5章int i,j,n,a1616; /*全局定义方阵行、列、阶数以及最大方阵容量*/void creat() /*建立魔方阵*/ int k; j=n/2+1; a1j=1; for(k=2;=n*n; i=i-1; j=j+1; if(in) i=i+2; j=j-1; if(in) j=1; if(aij=0) aij=k;void print() /*输出魔方阵*/ for(i=
10、1;%5d,aij);void main() int k,p,m; while(1) p=1; while(p=1)请输入n(n=15,n是奇数)n if(n!=0)&(nch; while(ch) switch(ch) case 1: printf (nHUFF1: Huffman Code Compression Program.n 14-Aug-90 Bill Demas. Version 1.0nn printf( 压缩文件名: scanf(%sfile0); 生成文件名:file1); compress(file0,file1); ch=0 break;2nDHUFF: Huffma
11、n Code Decompression Program. 解压文件名: decompress(file0,file1);3 exit(0); default: cout void compress(char *f1,char *f2) if (ifile = fopen (f1, rb) != NULL) fseek (ifile, 0L, 2); file_size = (unsigned long) ftell (ifile); #ifdef VERBOSE printf (1) Getting Frequency Counts.n #endif fseek (ifile, 0L, 0)
12、; get_frequency_count ();(2) Building Initial Heap.n build_initial_heap ();(3) Building the Code Tree.n build_code_tree ();(4) Generating the Code Table.n if (!generate_code_table ()ERROR! Code Value Out of Range. Cannot Compress.n else(5) Compressing & Creating the Output File.n if (ofile = fopen (
13、f2, wb fwrite (&file_size, sizeof (file_size), 1, ofile); fwrite (code, 2, 256, ofile); fwrite (code_length, 1, 256, ofile); fseek (ifile, 0L, 0); compress_image (); fclose (ofile); else printf(nERROR: Couldnt create output file n compression_report (); fclose (ifile); - File not found!void decompre
14、ss(char *f1,char *f2) /解压 fread (&file_size, sizeof (file_size), 1, ifile); fread (code, 2, 256, ifile); fread (code_length, 1, 256, ifile);(1) Building the tree.n build_decomp_tree ();(2) Decompressing & if (ofile = fopen (f2, decompress_image(); fclose (ofile); printf ( fclose (ifile);/decompressv
15、oid build_decomp_tree () register unsigned short loop1; register unsigned short current_index; unsigned short loop; unsigned short current_node = 1; decomp_tree1 = 1; for (loop = 0; loop 0; loop1-) current_index = (decomp_treecurrent_index loop1) & 1); if (!(decomp_treecurrent_index) decomp_treecurrent_index = +current_node; decomp_tree(decomp_treecurrent_i
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1