随笔分类 -  DSaA

深入理解递归函数的调用过程
摘要:下面是个关于递归调用简单但是很能说明问题的例子:/*递归例子*/#include<stdio.h>void up_and_down(int);int main(void){ up_and_down(1); return 0;}void up_and_down(int n){ printf("Level %d:n location %p/n",n,&n); /* 1 */ if(n<4) up_and_down(n+1); printf("Level %d:n location %p/n",n,&n); /* 2 */} 阅读全文

posted @ 2010-06-30 21:59 生活不是用来挥霍的

SeqList
摘要://工程名:SeqList//文件名:SeqList.h//功能:演示循序表的基本操作//依赖文件:SeqList.cpp,main.cpp#ifndefSeqList_H#defineSeqList_HconstintMaxSize=100;template<classT>classSeqList...{public:SeqList()...{length=0;}SeqList(Ta[],intn);voidInsert(inti,Tx);TDelete(inti);intLocate(Tx);voidPrintList();private:Tdata[MaxSize];intl 阅读全文

posted @ 2007-06-29 15:22 生活不是用来挥霍的

恺撒加密算法
摘要://工程名:KaiSa//文件名:KaiSa.cpp//功能:演示恺撒加密算法//依赖文件:无#include<iostream>#include<string>usingnamespacestd;//要用string就要有这么一句,不能用#include<iostream.h>;voidKaiSa(stringS,intk)...{charT[10];T[0]=S.length()+1;for(inti=0;i<S.length();i++)T[i+1]=(S[i]-97+k)%26+97;for(i=1;i<T[0];i++)cout< 阅读全文

posted @ 2007-06-28 12:26 生活不是用来挥霍的

Hanoi
摘要://工程名:Hanoi//文件名:Hanoi.cpp//功能:汉诺塔递归求解//依赖文件:无#include <iostream.h>#include <string.h>int count=0;void Hanoi(int n,char A,char B,char C){if(n==1){count++;cout<<"第"<<count<<"步:";cout<<A<<"->"<<C<<endl;}else{Hanoi(n 阅读全文

posted @ 2007-06-25 22:09 生活不是用来挥霍的

Election方法2
摘要://工程名:Election//文件名:Election.cpp//功能:统计候选人的投票数//依赖文件:无#include <string.h>#include <iostream.h>const int n=3;const int LEN=10;struct Person{char *name;int count;}Leader[n];Person *Create(const char *name,int num){Person *p = new Person;int mn = strlen(name);p->name = new char[mn+1];str 阅读全文

posted @ 2007-06-25 21:44 生活不是用来挥霍的

Election方法1
摘要:方法1://工程名:Election//文件名:Election.cpp//功能:统计候选人的投票数//依赖文件:无#include<iostream>#include<string>usingnamespacestd;constintn=3;//假设有3个候选人structPerson...{stringname;intcount;}Leader[n];voidElection(PersonLeader[],intn)...{stringname;cout<<"请输入候选人名为其投票:";cin>>name;while(na 阅读全文

posted @ 2007-06-23 19:37 生活不是用来挥霍的