esd笔试面试cuinx基础50个_第1页
esd笔试面试cuinx基础50个_第2页
esd笔试面试cuinx基础50个_第3页
esd笔试面试cuinx基础50个_第4页
esd笔试面试cuinx基础50个_第5页
已阅读5页,还剩22页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

if(if(flag{}{}if(0if(0!=flag{}{}if(if(NULL==flag{}{}ifif((flag>=NORM)&&(flag<=NORM){ 数组做sizeof的参数不退化,传递给strlen是sizeof。4:CstaticC++static在CstaticC++中除了上述功能外,还用来定而C++的静态成员则可以在多个对象实例间进行通信,传递信息。new、delete返回的是某种数据类型指针,malloc、free返回的是void#define 一个指向一个buffer的指针时,必须用volatile来修饰这个指针。voidmain(void){intintvoidmain(void){intint*ptr=(int}因为有系统会善后。例如全局变量,static变量等。mallocnew申请任意大小的内存,程序员自己负责在何符串的转化,memcpy主要是内存块间的拷贝。intintptr=(int*ptr=protection(privateprotected,templatetemplate<typenameT>class{A()~A()classB:virtualpublic{B()~B()classC:virtualpublic{C()~C()voidmain(void{B//Cc;}classA{{virtualvoid{cout<<"A::g"<<}virtualvoid{cout<<"A::f"<<}classB:public{void{cout<<"B::g"<<}virtualvoid{cout<<"B::h"<<}typedefvoid(*Fun)(void);voidmain(){BFunfor(inti=0;i<3;{pFun=(Fun)*((int*)*(int*)(&b)+i);}}编译器发现一个类中有虚函数,便会立即为此类生成虚函数表vtable。虚函数表的各表项为指向对置上)vptrvtable的vptrvtablevtable联系了起来。另外在调用类的构造函数时,ListList{{}listcur= listpre= listpre.nextpre.next=while(NULL!=cur.next{tmp=pre=tmp;cur=}return}ListList*reverse(List*oldList,List*newHead=NULL{List*nextoldList oldList->next=newHead; newHead=oldList; return(next==NULL)?newHead:reverse(t,newHead}配释放,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈。堆一般由程序员分配释放,若程序员不释放,程序结束时可能由OS回收。分配方式类似于链表。typedeftypedefstruct{intdata;{S=(LinkStack)malloc(sizeof(node));if(NULL==S){printf("Failtomallocanewreturnreturn}S->data=S->next=}LinkStackLinkStackPush(LinkStack&S,int{if(NULL=={printf("Therenonodeinstack!");returnNULL;}LinkStackp=p=(LinkStack)malloc(sizeof(node));if(NULL==p){printf("Failtomallocanewnode.\n");returnS;}if(NULL==S-{p->next=}{p->next=S-}p->data=S->next }nodenodePop(LinkStack{nodetemp;temp.data=0;if(NULL=={printf("Therenonodeinstack!");returntemp;}temp=if(if(S->next==NULL{printf("ThestackisNULL,can'tpop!\n");returntemp;}LinkStackp=S-temp=*p;free(p);}LinkStackLinkStackStackToQueuPush(LinkStack&S,int{nodeLinkStackS1= while(NULL!=S->next{n=Pop(S);}Push(S1,datawhile(NULL!=S1->next{n=Pop(S1);}}intintdepth(BiTree{if(!T)returnintintd1=depth(T->lchild);return}voidmain(void){intARRAY[10]={0,6,3,2,7,5,4,9,1,8intfor(i=0;i<10;{cout<<ARRAY[i]<<"}for(i=2;i<=10;i++{将{ARRAY[0]=j=i-j--;}while(ARRAY[0]<ARRAY[j]}}for(i=0;i<10;{cout<<ARRAY[i]<<"}}#defineLEN10voidmain(void){intARRAY[10]={0,6,3,2,7,5,4,9,1,8printf("\n"for(inta=0;a<LEN;a++{printf("%d",ARRAY[a]}inti=0;intj=boolfor(i=1;i<LEN;i++{isChange=for(j=LEN-1;j>=i;j--{if(ARRAY[j+1]<ARRAY[j]{ARRAY[j+1]=ARRAY[j];ARRAY[j]=ARRAY[0];isChange=}}printf("\n"for(a=0;a<LEN;{printf("%d",ARRAY[a]}if(!isChange{}}}#defineLEN9voidmain(void){intARRAY[LEN]={5,6,8,2,4,1,9,3,7for(intm=0;m<LEN;m++{printf("%d",ARRAY[m]}for(inti=1;i<=LEN-1;{intt=i-1;for(intj=i;j<LEN;{if(ARRAY[j]<{t=}}if(t!=(i-{temp=ARRAY[i-1];ARRAY[i-1]=ARRAY[t];ARRAY[t]=}}printf("\n");for(i=0;i<LEN;i++{printf("%d",ARRAY[i]}printf("\n"}#include voidcreateHeep(intARRAY[],intsPoint,int {while((2*sPoint+1)<Len{intmPoint=2*sPoint+1;if((2*sPoint+2)<Len{if(ARRAY[2*sPoint+1]<ARRAY[2*sPoint+2]{mPoint=}}if(ARRAYsPointARRAYmPoint {inttmpDataARRAYsPoint ARRAY[sPoint]=ARRAY[mPoint];ARRAY[mPoint]=tmpData;}{}}

sPoint=mPoint }voidheepSort(intARRAY[]intLen {intforiLen21i0i 将{createHeep(ARRAY,i,}for(i=Len-1;i>0;i--{inttmpData=ARRAY[0]; ARRAY[0]=ARRAY[i];ARRAY[i]=createHeepARRAY0i 将}}intmain(void{{intARRAY[]={5,4,7,3,9,1,6,8,for(inti=0;i<9;i++){printf("%d",}heepSort(ARRAY,9for(i=0;i<9;i++){printf("%d",ARRAY[i]}return0;}#include<stdio.h>#include<stdio.h>#defineLEN8typedefstructnode{intstructnode*typedefstruct{QueueNode( {Q=Q=(QueueLink)malloc(sizeof(Queue));if(NULL==Q){printf("Failtomallocnullqueue!\n");returnNULL;}Q->front=(QueueNode)malloc(sizeof(node));Q->rear=(QueueNode)malloc(sizeof(node));if(NULL==Q->front||NULL==Q->rear){printf("Failtomallocanewqueue'sforntorrear!\n");returnNULL;}Q->rear=return}intlenDatanodedataint {intm=0;inttemp=0;intd;for(inti=0;i<len;{while(d>0){d/=10;}if(temp>m{m=}temp=}return}QueueLinkPushQueueLink&Qnodenode {QueueNodep=(QueueNode)malloc(sizeof(node));if(NULL==p){printf("Failtomallocanewnode!\n");returnNULL;}p1=Q-while(p1->next!={p1=p1-}p1->next=p;p->next=Q-return}nodePopQueueLink {nodetemp;temp.data=0;QueueNodep;if(p!=Q->rear){temp=Q->front->next=p->next;free(p);p=}}intIsEmpty(QueueLink{{return}return}intmain(void{inti=intMax=0; intd=10;intpower=1;intk=0;nodeArray[LEN450NULL32,NULL781,NULL57NULL},for(i=0;i<10;i++){( }for(i=0;i<LEN;{printf("%d}Max=lenData(Array,LEN); for(intfor(intj=0;j<Max;{if(j==0)power=elsepower=powerfor(i=0;i<LEN;{k=Array[i].data/power-(Array[i].data/(power*d))*d;Push(Queue[k],Array[i]);}for(intl0k0ld; {while(IsEmpty(Queue[l]){Array[k++]=Pop(Queue[l]}}for(intt=0;t<LEN;{printf("%d}}}30:shorti0;ii1L可预想的后果(比如当两个操作数一个是1另一个是2时)。条路径。打印出和与输入整数相等的所有路径。例如,输入整数9和如下二元树:3 typedeftypedefstruct{BiTNode*tree;voidvoidinitpath(pPath*L{*L=(pPath)malloc(sizeof(PATH));(*L)->next=NULL;}voidvoidpushpath(pPathH,pBTree{pPathq=H;while(NULL!=p{{q=p=p-}p=(pPath)malloc(sizeof(PATH));p->next=NULL;p->tree=q->next=}voidvoidprintpath(pPathL{pPathp=L-while(NULL!=p{p=p->next;}}voidvoidpop_path(pPathH{pPathq=H;if(NULL==p{}p=p->next;while(NULL!=p){q=q->next;p=p-}free(q->nextq->next=}{return(T->lchild==NULL)&&(T->rchild==NULL}intintfind_path(pBTreeT,intsum,pPath{{pushpath(L,T);if((record==sum)&&(IsLeaf(T)){printpath(L);printf("\n");}if(T->lchild!=NULL{findpath(T->lchild,sum,}if(T->rchild!=NULL{findpath(T->rchild,sum,}record-=T-poppath(L);return0;} 用法不同:typedef用来定义一种数据类型的别名,增强程序的可读性。define主要用来定义执行时间不同:typedef是编译过程的一部分,有类型检查的功能。define是宏定义,是预编作用域不同:typedef有作用域限定。definedefine声明后的引用const用来定义一个只读的变量或对象。主要优点:便于类型检查、同宏定义一样可以方便地进行说明:const修饰函数参数,是一种编程规范的要求,便

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论