已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年宠物美容服务行业战略咨询报告及未来五至十年研发投入与专利布局
- 小学英语教资面试阅读专项及解析
- CATTI口译考试全等级题型详解
- 2026辅警面试警械使用题目及答案
- 双碳背景下绿色耐心资本在能源结构转型中的金融工具创新
- 献礼儿童节:幼儿园投资计划书
- 三年级我们遵守规则
- 银行个人工作总结29篇
- 小学数学三年级上册《同级运算的运算顺序》课件
- 软件项目管理案例教程第2版
- 时空耦合分类模型构建-洞察及研究
- 2025年揭阳揭西县选调高中教师考试试题(含答案)
- 咯血患者介入治疗的护理讲课件
- GB/T 45472-2025架空和综合管廊用预制保温管道
- 急救与生命支持类设备管理
- 2025年湖北恩施州巴东县机关事业单位选调46人历年高频重点提升(共500题)附带答案详解
- 培训劳动纪律
- 如何做好临床护理带教组长
- 人教版六年级数学上册【全册教案】
- 车位租赁协议
- 做有梦想的少年 课件-2024-2025学年统编版道德与法治七年级上册
评论
0/150
提交评论