自己整理的c面试常考程序题

自己整理的c面试常考程序题

ID:1771584

大小:32.34 KB

页数:12页

时间:2017-11-13

自己整理的c面试常考程序题_第1页
自己整理的c面试常考程序题_第2页
自己整理的c面试常考程序题_第3页
自己整理的c面试常考程序题_第4页
自己整理的c面试常考程序题_第5页
资源描述:

《自己整理的c面试常考程序题》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、1./*字符串倒置*/#include#includevoidfunc(char*str){intbeg,end;chartem;for(beg=0,end=strlen(str)-1;beg

2、2./*约瑟夫问题*/#include#includestructNode{intdata;structNode*next;};intmain(){intm,n,i;printf("inputnumber:");scanf("%d",&m);structNode*head,*r,*p,*q;head=(structNode*)malloc(sizeof(structNode));p=head;for(i=1;i<=m;i++){r=(structNode*)mal

3、loc(sizeof(structNode));r->data=i;p->next=r;p=r;}p->next=head->next;p=p->next;printf("startis:");scanf("%d",&n);intj=1;while(jnext;j++;}ints;printf("间隔为:");scanf("%d",&s);do{for(i=1;i<=s-1;i++)p=p->next;q=p->next;printf("%d",q->data);p->next=q-

4、>next;free(q);p=p->next;m--;}while(m>0);return0;}3./*String类的实现*/#include#includeusingnamespacestd;classString{public:String(constchar*data=NULL){if(data==NULL){m_data=newchar[1];*m_data='';}else{m_data=newchar[strlen(data)+1];strc

5、py(m_data,data);}}String(constString&other){m_data=newchar[strlen(other.m_data)+1];strcpy(m_data,other.m_data);}~String(void){delete[]m_data;}String&operator=(constString&other){if(this==&other)return*this;delete[]m_data;m_data=newchar[strlen(other.m_da

6、ta)+1];strcpy(m_data,other.m_data);}voidprint(void){puts(m_data);}private:char*m_data;};intmain(){Strings("liushaohui");s.print();Stringp(s);p.print();String*t=newString("haojiahuo");t->print();Stringq;q=s;q.print();return0;}4./*定义一个Person类,实现堆的功能*/#inc

7、ludeusingnamespacestd;classPerson{public:Person(void):m_head(NULL){}~Person(void){Node*p;while(m_head){p=m_head->m_next;deletem_head;m_head=p;}}voidPush(constchar*name,intage){m_head=newNode(name,age,m_head);}voidPop(void){if(!m_head)return;el

8、se{Node*p=m_head->m_next;printf("%s,%d",m_head->m_name,m_head->m_age);deletem_head;m_head=p;}}private:classNode{public:Node(constchar*name=NULL,intage=0,Node*next):m_name(newchar[strlen(name)+1]),m_age(age),m_next(next){strcpy(

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。