ImageVerifierCode 换一换
格式:DOCX , 页数:18 ,大小:20.69KB ,
资源ID:1662329      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-1662329.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(软考程序员算法实例.docx)为本站会员(b****2)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

软考程序员算法实例.docx

1、软考程序员算法实例软考程序员算法实例:二叉树的中序输出问题这个程序的思路是自己输入数字,在输入的同时,已经帮你左右顺序排好了,即左子树的数字比右子树小,是个顺序二叉树,以输入0为结素,而后一中序遍历输出,但不知道为什么,在屏幕上打引的却是左子树最小的数字,而且一直输出,请看下面程序:#include #include typedef struct noint key;struct no *left,*right;node,*PNOD;void inster(PNOD *p,int k)PNOD ppre,pre,temp;ppre=*p;printf(“current number ppre

2、% d”,ppre-key);if(ppre=NULL)ppre=(node *)malloc(sizeof(node);ppre-key=k;ppre-left=NULL;ppre-right=NULL;*p=ppre;return;while(ppre)if(k key)temp=ppre;ppre=ppre-left;printf(“leftn”);else if(k = ppre-key)printf(“has n”);return;else if(k ppre-key)temp=ppre;ppre=ppre-right;printf(“rightn”);/*printf(“aaaaa

3、aaaaaaaaaaaaa”);*/pre=(node *)malloc(sizeof(node);pre-key=k;pre-left=NULL;pre-right=NULL;if(temp-key k)temp-left=pre;elsetemp-right=pre;PNOD creat()PNOD T=NULL;int k;printf(“please input number =”);scanf(“%d”,&k);while(k)inster(&T,k);printf(“nagain =”);scanf(“%d”,&k);return T;void found(PNOD t)PNOD

4、pp;pp=t;while(pp)printf(“pp-key=%d pp-left=%d pp-right=%d”,pp-key,pp-left-key,pp-right-key);printf(“n”);found(pp-left);printf(“”,pp-key);/*printf(“pp-left=%d and pp=%d”,pp-left,pp);*/getchar();found(pp-right);main()PNOD T=NULL;printf(“*n”);T=creat();found(T);软考程序员算法实例:全排列的递归算法using System;namespace

5、TotalSort/*/ / 全排列的递归算法/ class Class1/*/ / 应用程序的主入口点。/ STAThreadstatic void Main(string args)/char s = abcdefghijklmnopqrstuvwxyz.ToCharArray();char s = abcde.ToCharArray();TotalSort(s, 0);Console.WriteLine(nn总数:0, resultCount);Console.ReadLine();static int resultCount = 0;public static void TotalSo

6、rt(char list, int start) int end = list.Length - 1;if (start = end) resultCount+;Console.WriteLine(list);else for (int i = start; i temp&low寻找小于temp的数high-;if(low=high)break;elsearraylow=arrayhigh;low+;while(arraylow寻找大于temp的数low+;if(low=high)break;elsearrayhigh=arraylow;high-;arraylow=temp; /最终low=

7、high作为划分点,并将划分数存于arraylowreturn low;思想:就是你从数组中任取一个元素p(可随机取,现在以取第一个为例);以P作为主元,对数组 进行划分 ,前一部分小于 P,后一部分大于p;最后划分处存储 p;然后分别对划分后的前一部分和后一部分递归调用;算法平均时间复杂度: O(nlogn)。软考程序员算法实例:C语言二路归并排序lovethea 8585人关注 Thea 更新:2011/4/9查看评论(0)给我发信息免费做试题学习交流写了个二路归并的归并排序小代码,直接贴上来:/* file:quick.cpp author: */ #include using name

8、space std; void Merge(int a,int low,int mid,int high,int b); void MSort(int a,int low,int high,int b); void main() int a=4,5,9,10,51,6,46,36,6,56,67,45,36; int b13; MSort(a,0,12,b); for(int i=0;i13;i+) coutbi ; coutendl; for(int j=0;j13;j+) coutaj ; coutendl; void Merge(int a,int low,int mid,int hig

9、h,int b) int i=low,j=mid+1,k=low; while(i=mid)&(j=high) if(ai=aj) bk=ai; i+; else bk=aj; j+; k+; while(i=mid) ak=ai; k+; i+; while(j=high) ak=aj; k+;j+; void MSort(int a,int low,int high,int b) if(low=high) blow=alow; else int mid=(low+high)/2; MSort(a,low,mid,b); MSort(a,mid+1,high,b); Merge(a,low,

10、mid,high,b); 软考程序员算法实例:朴素字符串匹配算法lovethea 8585人关注 Thea 更新:2011/4/9查看评论(0)给我发信息免费做试题学习交流作为最原始的字符串匹配算法,它的时间复杂度是O(n-m+1)m)#include stdio.h/计算字符串的长度int Length(char *s)int count=0;while(*s+!=0)count+;return count;/字符串匹配void NaiveStringMatching(char *t,char *p)int n=Length(t);int m=Length(p);if(nM) printf(

11、Error:The P is longer than T!n);return;bool find=true;printf(The string T is %sn,t);printf(The string P is %sn,p);for(int s=0;s=n-m;s+)find=true;for(int i=0;iM;I+) if(ts+i!=pi)find=false;break;if(find)printf(Pattern occurs with shift:%dn,s+1);int main()char t=abcdebcg;char p=bcdebcg;NaiveStringMatch

12、ing(t,p);return 0;软考程序员算法实例:二路归并排序算法lovethea 8585人关注 Thea 更新:2011/4/9查看评论(0)给我发信息免费做试题学习交流写了个二路归并的归并排序小代码,直接贴上来/*file:quick.cppauthor:*/#includeusing namespace std;void Merge(int a,int low,int mid,int high,int b);void MSort(int a,int low,int high,int b);void main()int a=4,5,9,10,51,6,46,36,6,56,67,4

13、5,36;int b13;MSort(a,0,12,b);for(int i=0;i13;i+)coutbi ;coutendl;for(int j=0;j13;j+)coutaj ;coutendl;void Merge(int a,int low,int mid,int high,int b)int i=low,j=mid+1,k=low;while(i=mid)&(j=high)if(ai=aj)bk=ai;i+;elsebk=aj;j+;k+;while(i=mid)ak=ai;k+;i+;while(j=high)ak=aj;k+;j+;void MSort(int a,int lo

14、w,int high,int b)if(low=high)blow=alow;elseint mid=(low+high)/2;MSort(a,low,mid,b);MSort(a,mid+1,high,b);Merge(a,low,mid,high,b); 软考程序员算法实例:矩阵求逆算法/* 求矩阵A的逆矩阵Ai*param A 源矩阵*param Ai 逆矩阵*param size 矩阵的大小*return 求解成功返回非零值,失败返回零*/int InverseMatrix(double *Ai, double *A, int size)int i, j;double *b, *x;b = (double*)malloc(sizeof(double)*size);x = (double*)malloc(sizeof(double)*size);for (i = 0; i size; i+)memset(b, 0, sizeof(double)*size);bi = 1;if (!LinearEquation(A, x, b, size)free(b);free(x);return 0;for (j = 0; j size; j+)Aiji = xj;free(b);free(x);return 1;

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2