




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
經(jīng)典筆試題1.冒泡排序voidBubbleSort(intarray[],intlen){inti=0;intj=0;intexchange=1;for(i=0;(i<len)&&exchange;i++){exchange=0;for(j=len-1;j>i;j--){if(array[j]<array[j-1]){swap(array,j,j-1);exchange=1;}}}}2.插入排序voidInsertionSort(intarray[],intlen){inti=0;intj=0;intk=-1;inttemp=-1;for(i=1;i<len;i++){k=i;temp=array[k];for(j=i-1;(j>=0)&&(array[j]>temp);j--){array[j+1]=array[j];k=j;}array[k]=temp;}}
3.選擇排序voidSelectionSort(intarray[],intlen){inti=0;intj=0;intk=-1;for(i=0;i<len;i++){k=i;for(j=i;j<len;j++){if(array[j]<array[k]){k=j;}}swap(array,i,k);}}4.字符串求長(zhǎng)size_tstrlen(constchar*s){size_tlength=0;assert(s);while(*s++){length++;}returnlength;}5.字符串復(fù)制char*strcpy(char*dst,constchar*src){char*ret=dst;assert(dst&&src);while((*dst++=*src++)!='\0');returnret;}6.字符串連接voidstrcat(chars[],chart[]){ inti,j; i=j=0; while(s[i]!=’\0’) i++; while((s[i++]=t[j++])!=’\0’) ;}7.字符串比較intstrcmp(char*source,char*dest){assert(source&&dest);while((*source==*dest)&&(*source)&&(*dest)){source++;dest++;}if((*source=='\0')&&(*dest=='\0'))return0;elsereturn-1;}8.字符串反轉(zhuǎn)voidreverse(chars[]){ intc,i,j; for(i=0,j=strlen(s)-1;i<j;i++,j--){ c=s[i]; s[i]=s[j]; s[j]=c; }}9.字符串轉(zhuǎn)數(shù)字intatoi(chars[]){inti,n,sign;for(i=0;isspace(s[i]);i++) ;sign=(s[i]==’-’)?-1:1;if(s[i]==’+’||s[i]==’-’) i++;for(n=0;isdigit(s[i]);i++)n=10*n+(s[i]-’0’);returnsign*n;}10.數(shù)字轉(zhuǎn)字符串voiditoa(intn,chars[]){ inti,sign; if((sign=n)<0) n=-n; i=0; do{ s[i++]=n%10+’0’;}while((n/=10)>0);if(sign<0) s[i++]=’-’;s[i]=’\0’;reverse(s);}11.二分查找intbinary_search(inta[],intlow,inthigh,intkey){intret=-1;while(low<=high){intmid=(low+high)/2;if(a[mid]==key){ret=mid;break;}elseif(key<a[mid]){high=mid-1;}elseif(key>a[mid]){low=mid+1;}}returnret;}
12.內(nèi)存復(fù)制void*memcpy(void*dest,constvoid*src,size_tcount){assert(dest!=NULL&&src!=NULL);char*tmp=(char*)dest;constchar*s=(constchar*)src;while((count--)>0)*tmp++=*s++;returndest;}13.最長(zhǎng)公共子串intLCS(constchar*str1,intlen1,constchar*str2,intlen2,char*&lcs){if(NULL==str1||NULL==str2){return-1;}int*c=newint[len2+1];for(inti=0;i<len2;++i){c[i]=0;}intmax_len=0;intpos=0;for(inti=0;i<len1;++i){for(intj=len2;j>0;--j){if(str1[i]==str2[j-1]){c[j]=c[j-1]+1;if(c[j]>max_len){max_len=c[j];pos=j-1;}}else{c[j]=0;}}}if(0==max_len){return0;}lcs=newchar[max_len];for(inti=0;i<max_len;++i){lcs[i]=str2[pos-max_len+1+i];}cout<<"pos="<<pos<<endl;delete[]c;returnmax_len;}14.約瑟夫問(wèn)題voidarray_iterate(intlen,intinput_array[],intm,intoutput_array[]){ bool*flag=newbool[len]; memset(flag,false,len);inthasout=0;//已經(jīng)出列旳數(shù)字旳個(gè)數(shù) intpos=0;//目前元素旳下標(biāo) intcount=0;//目前已數(shù)到旳未被標(biāo)識(shí)旳數(shù)字旳個(gè)數(shù)while(1) { if(false==flag[pos])//目前元素還沒(méi)有出列{count++;if(count==m)//已經(jīng)計(jì)數(shù)到m,input_array中pos下標(biāo)旳元素出列{output_array[hasout]=input_array[pos];flag[pos]=true;//標(biāo)識(shí)input_array中pos下標(biāo)旳元素已經(jīng)出列hasout++;if(hasout==len) break;//所有旳元素都已經(jīng)出列,退出本函數(shù)//初始化下一輪旳數(shù)字count=0;m=input_array[pos];}} pos=(pos+1)%len;}delete[]flag;}15.單鏈表旳創(chuàng)立struct_tag_node{intdata;struct_tag_node*next;};typedefstruct_tag_nodenode;node*creat(void){node*head;node*tail;node*temp;intv;head=(node*)malloc(sizeof(node));tail=head;while(1){printf("pleaseinputthedata:");scanf("%d",&v);if(v!=0){temp=(node*)malloc(sizeof(node));temp->data=v;tail->next=temp;tail=temp;}elsebreak;}tail->next=NULL;head=head->next;returnhead;}16.單鏈表旳測(cè)長(zhǎng)intlength(node*head){intn=0;node*p=head;while(p!=NULL){p=p->next;n++;}returnn;}17.單鏈表旳打印voidprint(node*head){node*p=head;if(head!=NULL){while(p!=NULL){printf("%d->",p->data);p=p->next;}}printf("NULL\n");}18.單鏈表旳節(jié)點(diǎn)刪除node*del(node*head,intpos){node*p1=head;node*p2;if(pos>=0&&pos<length(head)){inti;for(i=0;i<pos;i++){p2=p1;p1=p1->next;}if(p1==head){head=p1->next;free(p1);}else{p2->next=p1->next;free(p1);}}returnhead;}19.單鏈表旳節(jié)點(diǎn)插入node*insert(node*head,intpos,intv){if(pos>=0){node*temp=(node*)malloc(sizeof(node));temp->data=v;if(pos==0||head==NULL){temp->next=head;head=temp;}else{node*p1=head;node*p2;for(inti=0;(i<pos)&&(p1!=NULL);i++){p2=p1;
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 急救人員裝備準(zhǔn)備計(jì)劃
- 2025年IC卡售氣系統(tǒng)項(xiàng)目合作計(jì)劃書(shū)
- 2025年物料搬運(yùn)機(jī)械項(xiàng)目合作計(jì)劃書(shū)
- 毛石擋土墻砌筑工程施工合同
- 智能投顧服務(wù)平臺(tái)開(kāi)發(fā)合作協(xié)議
- 視頻抖音廣告合同
- 內(nèi)部通知文件(調(diào)整辦公時(shí)間)
- 某項(xiàng)目執(zhí)行情況回顧與反思
- 磚廠股份轉(zhuǎn)讓協(xié)議書(shū)
- α-Amyrin-Standard-生命科學(xué)試劑-MCE
- 小孩使用手機(jī)協(xié)議書(shū)范本
- 2024年海南省高考物理試卷(含答案)
- 榆神礦區(qū)郭家灘煤礦(700 萬(wàn)噸-年)項(xiàng)目環(huán)評(píng)
- 2024年200MW-400MWh電化學(xué)儲(chǔ)能電站設(shè)計(jì)方案
- GJB5765-2006 軍用機(jī)場(chǎng)場(chǎng)道工程質(zhì)量評(píng)定標(biāo)準(zhǔn)
- 余土外運(yùn)施工方案
- DB32-T 186-2015建筑消防設(shè)施檢測(cè)技術(shù)規(guī)程
- 中考英語(yǔ)1600詞匯對(duì)照表-(帶音標(biāo))
- 虛擬化與云計(jì)算技術(shù)應(yīng)用實(shí)踐項(xiàng)目化教程 課件全套 陳寶文 項(xiàng)目1-8 虛擬化與云計(jì)算導(dǎo)論- 騰訊云服務(wù)
- (正式版)JBT 7248-2024 閥門(mén)用低溫鋼鑄件技術(shù)規(guī)范
- 2024廣東高壓電工考試電工證考試題模擬試題(全國(guó)版)
評(píng)論
0/150
提交評(píng)論