摘要: //考察点1:输入参数加constint Mystrlen(const char *str){//考察点2:断言字符串非0 assert(str!=NULL); int len=0;//考察点3:一定要初始化 while((*str++)!='\0') {len++; } return len;} 阅读全文
posted @ 2013-10-27 22:39 编程的爬行者 阅读(184) 评论(0) 推荐(0) 编辑
摘要: char *Mystrcpy(char *strDest, const char *strSrc)//考察点1:将源字符串加const,表明为输入参数{//考察点2:对源地址和目的地址的非0断言 assert((strDset!=NULL) && (strSrc!=NULL)); char *address=strDest; while((*strDest++=*strSrc++)!='\0') return address;//考察点3:为了实现链式操作,返回目的地址} 阅读全文
posted @ 2013-10-27 22:35 编程的爬行者 阅读(215) 评论(0) 推荐(0) 编辑
摘要: //计算正整数算术表达式可分两个步骤1)将中缀表达式转换成后缀表达式;2)计算后缀表达式的值#include using namespace std;#define Maxsize 20//1)将中缀表达式转换成后缀表达式;void trans(char *exp,char postexp) //将exp转换成postexp{ struct { char data[Maxsize];// int top;//栈指针 }op;//运算符栈int i=0;//postexp的下标 op.top=-1;while(*exp!='\0') { switch(*exp) { case&# 阅读全文
posted @ 2013-10-27 16:38 编程的爬行者 阅读(277) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std;#define Maxsize 100typedef int ElemType;typedef struct{ ElemType data;//数字域 int next;//游标域}StaticList[Maxsize];void CreateList(StaticList L, ElemType a[], int n){ L[0].next=1; for(int i=1;i<=n;i++) { L[i].data=a[i-1]; L[i].next=i+1; } L[n].next=0;}void Display(StaticL 阅读全文
posted @ 2013-10-26 15:35 编程的爬行者 阅读(422) 评论(0) 推荐(0) 编辑
摘要: //单链表的头插法和尾插法建立,以及直接插入法递增排序#include #include #include #define ElemType intusing namespace std;typedef struct List{ ElemType data; struct List *next;}List;void CreatListF(List *L,ElemType a[],int n){ List *s; L->next=NULL; int i; for(i=0;idata=a[i];s->next=L->next;L->next=s;}}void CreatLi 阅读全文
posted @ 2013-10-25 15:40 编程的爬行者 阅读(153) 评论(0) 推荐(0) 编辑
摘要: void movel(SqList *&L){ int i=0; int j=L->LENGTH-1; ElemType qivot=L->data[0]; whlie(i!=j) { while(j>i && L->data(j)>qivot) j--;L->data[i]=L->data[j]; while(idata[i]data[j]=L->data[i];}L->data[i]=qivot;} 阅读全文
posted @ 2013-10-24 22:06 编程的爬行者 阅读(130) 评论(0) 推荐(0) 编辑
摘要: //如3,121,313,34443,12121都是回文数#include using namespace std;int judge(int m){//首先将输入的整数m按每位进行存储//假设m=12121,则定义数组a[5]={1,2,1,2,1} int temp,a[10]; int i,t;//i存储为m的位数,t为每位上的具体数字 temp=m; while(temp!=0) { t=temp%10; a[i]=t; temp=temp/10; i++; } int *p=a;int *q=a+i-1; while(p>m; Judge(m);system("pau 阅读全文
posted @ 2013-10-23 12:50 编程的爬行者 阅读(198) 评论(0) 推荐(0) 编辑
摘要: //club函数模拟一个俱乐部的顾客,初始化情况下是0个顾客,俱乐部内只能容纳有限个数的顾客,假设为50.当用户超过50,则必须在外面等待。当一些顾客离开时,等待队列将减少。用club函数打印在俱乐部内部的人数和在外面等待的人数,编写代码如下:#include using namespace std;#define MAX_IN_CUSTOM (50)void int club(int x){//若果外面来的客人分两种情况x>=0和x0) {//大于0的情况下再分为两种子情况in_custom+x>=MAX_IN_CUSTOM和小于的情况 if(x+in_custom>=MA 阅读全文
posted @ 2013-10-23 10:59 编程的爬行者 阅读(146) 评论(0) 推荐(0) 编辑
摘要: //输入一个整数n,输出2到n之间的具体素数值#include #include #include using namespace std;int Juge(int n){ int j; for(j=2;j>n; cout<<"素数是:"; for(i=1;i<=n;i++) { if(Judge(i)==0)cout<<i<<" ";} system("pause"); return 0;} 阅读全文
posted @ 2013-10-22 11:23 编程的爬行者 阅读(355) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std;#define max(a,b) ((a)>(b)?(a):(b))#define abs(a) ((a)>0?(a):(-a))#define square(a) ((a)*(a))int Spiral_Queue(int x,int y){ int t=max(abs(x),abs(y));int val; if(y==-t)//北边线 增长从左往右与横坐标方向一致 (2t-1).^2+7t+x val=square(2*t-1)+7*t+x; if(y==t)//南边线 增长从右至左与横坐标方向相反 (2t-1).^2 阅读全文
posted @ 2013-10-22 10:39 编程的爬行者 阅读(162) 评论(0) 推荐(0) 编辑