




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
一、 Sizeof关键字的用法#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个字符*/ printf(%dn,sizeof(p); /*size(p)是求指针变量p的长度,指针变量p存放的是一个地址,32位的机器的一个地址是32位(即4个人字节),16位的机器是16位(2个字节)。*/ printf(%dn,sizeof(n); /*一个整形变量int的存储长度为:32位机器4个字节,16位机器2个字节。*/ func(str); /*sizeof(str)求str地址长度*/二、 单链表的操作#include /以下为链表的定义 struct node /节点的定义 int data;struct node *next;class Linklist /单向链表的定义 private: int size; /链表的大小 struct node *head,*bottom; /链表的头,尾指针 struct node *pos(int location); /返回指向location位置的指针 public: Linklist(); /构造函数 Linklist(const Linklist &); /拷贝构造函数 似乎有问题 Linklist(); bool ins(const int &member,int location=-1); /向链表中location位置插入元素,0,表示开头插入,-1,表示末尾插入 int del(int location); /删除链表中location位置节点,并返回被删元素 int find(const int &member,int begin); /从begin位置开始,找出member第一次出现的位置,并返回该位置 int rep(const int &member,int location); /用memebr替换掉location位置上的元素,并返回被替换元素 void cle(void); /清空链表 int get(int location); /返回location位置的元素 int get(void); /返回链表的大小 ;/以下为链表的实现 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;【题目】使用递归实现阶乖【代码】#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”中的第一个字“.”字符替换成“_”int main(int argc, _TCHAR* argv)char str100 = abc.bdc.d
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 电石炉培训知识课件
- 2.5直线与圆的位置关系 分层练习(含答案)数学苏科版九年级上册
- 北民大附中开学考试题及答案
- 高热危重患者护理课件
- Linoleic-acid-suitable-for-cell-culture-生命科学试剂-MCE
- 2-Methylleucine-CoA-2-Methylleucine-coenzyme-A-生命科学试剂-MCE
- 北海高中分班考试试卷及答案
- 电焊工基础知识培训课件
- 高温季节安全知识培训课件
- 音序考试题及答案
- 工业厂房租赁管理办法
- 2025年综合类-农艺师考试-农艺师考试-园艺工考试-高级花卉工考试历年真题摘选带答案(5卷100题)
- 辽宁动物检疫管理办法
- 小学六年级综合实践环境保护计划
- 肺癌免疫治疗病例分享
- 2025年汽车智能驾驶技术及产业发展白皮书-清华大学
- 2025云南师范大学辅导员考试题库
- 2025年国考行测试题及答案解析
- 联邦学习框架下的设备故障智能诊断算法研究
- 财务岗位安全培训课件
- 2025年贵州省中考语文试卷真题(含答案)
评论
0/150
提交评论