




已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
一、 Sizeof關(guān)鍵字的用法#include void func(char str100)printf(%dn,sizeof(str); ;void main() char str = Hello; char *p=str; int n=10; printf(%dn,sizeof(str); /*Hello0共6個(gè)字符*/ printf(%dn,sizeof(p); /*size(p)是求指針變量p的長(zhǎng)度,指針變量p存放的是一個(gè)地址,32位的機(jī)器的一個(gè)地址是32位(即4個(gè)人字節(jié)),16位的機(jī)器是16位(2個(gè)字節(jié))。*/ printf(%dn,sizeof(n); /*一個(gè)整形變量int的存儲(chǔ)長(zhǎng)度為:32位機(jī)器4個(gè)字節(jié),16位機(jī)器2個(gè)字節(jié)。*/ func(str); /*sizeof(str)求str地址長(zhǎng)度*/二、 單鏈表的操作#include /以下為鏈表的定義 struct node /節(jié)點(diǎn)的定義 int data;struct node *next;class Linklist /單向鏈表的定義 private: int size; /鏈表的大小 struct node *head,*bottom; /鏈表的頭,尾指針 struct node *pos(int location); /返回指向location位置的指針 public: Linklist(); /構(gòu)造函數(shù) Linklist(const Linklist &); /拷貝構(gòu)造函數(shù) 似乎有問題 Linklist(); bool ins(const int &member,int location=-1); /向鏈表中l(wèi)ocation位置插入元素,0,表示開頭插入,-1,表示末尾插入 int del(int location); /刪除鏈表中l(wèi)ocation位置節(jié)點(diǎn),并返回被刪元素 int find(const int &member,int begin); /從begin位置開始,找出member第一次出現(xiàn)的位置,并返回該位置 int rep(const int &member,int location); /用memebr替換掉location位置上的元素,并返回被替換元素 void cle(void); /清空鏈表 int get(int location); /返回location位置的元素 int get(void); /返回鏈表的大小 ;/以下為鏈表的實(shí)現(xiàn) bool Linklist:ins(const int &member,int location) struct node *temp,*p;if(locationsize|locationdata=member;size+;elseif(bottom-next=new struct node)=0) return false;bottom=bottom-next;bottom-data=member;size+; break;case 0:temp=head;if(head=new struct node)=0) return false;head-next=temp;head-data=member;size+; break;default:if(p=new struct node)=0) return false;temp=pos(location);p-data=member;p-next=temp-next;temp-next=p;size+;return true;node *Linklist:pos(int location)node *p=head;int i;if(location=1&location=size)for(i=1;inext;return p;return 0;int Linklist:del(int location) node *temp,*p;int member;if(head=0) return 100000;if(locationsize|locationnext=0;break;case 0:temp=head-next;member=head-data;delete head;size-;if(size=0) head=bottom=0;elsehead=temp;break;default:p=pos(location);temp=p-next;member=p-data;delete p;pos(location-1)-next=temp;size-;return member;int Linklist:find(const int &member,int begin)int i;node *p;if(head=0) return -1;p=pos(begin);for(i=begin;idata=member) return i;p=p-next;return -1;int Linklist:rep(const int &member,int location)int t;if(head=0) return 100000;t=pos(location)-data;pos(location)-data=member;return t;void Linklist:cle(void)int i;if(head=0) return;node *p,*t;p=head;head=bottom=0;for(i=0;inext;delete p;p=t;size=0;Linklist:Linklist()size=0;head=bottom=0;Linklist:Linklist()cle();Linklist:Linklist(const Linklist &l)int i;for(i=1;i=1&locationdata;int Linklist:get(void)return size;【題目】使用遞歸實(shí)現(xiàn)階乖【代碼】#include stdafx.h#include stdafx.hint recursion(int num)if(num = 1)return 1;elsereturn num * recursion(num - 1);int main(int argc, _TCHAR* argv)printf(%dn,recursion(4);getchar();return 0;【題目】把字符串“abc.bdc.dfs”中的第一個(gè)字“.”字符替換成“_”int main(int argc, _TCHAR* argv)char str100 = abc.bdc.d
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 城鎮(zhèn)污水管網(wǎng)建設(shè)項(xiàng)目建設(shè)管理方案(參考)
- xx河流排水防澇設(shè)施建設(shè)項(xiàng)目質(zhì)量管理方案(參考范文)
- 2025年非離子型纖維素醚項(xiàng)目合作計(jì)劃書
- 憲法知識(shí)學(xué)習(xí)題庫
- 2025年天貓養(yǎng)車項(xiàng)目發(fā)展計(jì)劃
- 下關(guān)穴治療疼痛的現(xiàn)代技術(shù)融合
- 無人駕駛電動(dòng)拖拉機(jī)平臺(tái)的設(shè)計(jì)及試驗(yàn)
- 現(xiàn)代泌尿腫瘤學(xué)閱讀筆記
- 2025年GPS高空探測(cè)系統(tǒng)項(xiàng)目發(fā)展計(jì)劃
- 文化旅游的發(fā)展
- 2025年貴州省中考語文試卷真題(含答案)
- 2025年廣西公需科目答案02
- 人教精通版五年級(jí)上學(xué)期Lesson25教學(xué)課件
- 魯教版九年級(jí)英語課文原文及翻譯Unit1
- 《工業(yè)固廢資源化技術(shù)及應(yīng)用》課程教學(xué)大綱
- [北京]輸變電工程標(biāo)準(zhǔn)工藝應(yīng)用圖冊(cè)(圖文并茂)
- 2020年雀巢公司北京總部十周年慶典暨雀巢家庭日活動(dòng)策劃案ppt課件
- 1000MW機(jī)組鍋爐長(zhǎng)伸縮式吹灰器檢修規(guī)程
- 清關(guān)發(fā)票裝箱單樣本
- 地下水八大離子-陰陽離子平衡計(jì)算公式
- 廣州人才綠卡申請(qǐng)表
評(píng)論
0/150
提交評(píng)論