- 1、本文档共56页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
[文学研究]数据结构与程序设计教师鲍钰
数据结构与程序设计 教师:鲍钰 数据结构与程序设计(7) 教师:鲍钰 ybao@sei.ecnu.edu.cn 第四章 Linked Stacks and Queues 问题的提出 P113 引入指针 Figure 4.1 指针声明 C++ uses an asterisk * to denote a pointer. If Item is a type, then a pointer to such an Item object has the type Item *. For example, Item *item_ptr; declares item_ptr as a pointer variable to an Item object. Creating dynamic objects Item_ptr = new Item; creates a new dynamic object of type Item and assigns its location to the pointer variable item_ptr. Deleting dynamic objects delete item_ptr; disposes of the dynamic object to which item_ptr points and returns the space it occupies to the free store so it can be used again. Following pointers *item_ptr denotes the object to which item_ptr points. NULL pointers If a pointer variable item_ptr has no dynamic object to which it currently refers, then it should be given the special value. Item_ptr = NULL; Uninitialized or random pointer objects should always be reset to NULL. After deletion, a pointer object should be reset to NULL. #includeiostream.h Dynamically Allocated Arrays Item_array = new Item[array_size]; creates a dynamic array of Item objects, indexed from 0 up to array_size ? 1. Dynamically Allocated Arrays for example: int size, *dynamic_array, i; cout Enter an array size: ; cin size; dynamic_array = new int[size]; for (i = 0; i size; i++) dynamic_array[i] = i; Dynamically Allocated Arrays Dynamically Allocated ArraysP120 Dynamically Allocated Arrays delete [] dynamic_array; returns the storage in dynamic array to the free store. 指针运算 If i is an integer value and p is a pointer to an Item, then p + i is an expression of type Item *. The value of p + i gives the memory address offset from p by i Item objects. That is, the expression p + i actually yields the address p + n*i, where n is the number of bytes of storage occupied by a simple object of type Item. Addresses of automatic objects If x is a variable of type Item, then x is a value of type Item * that gives the ad
您可能关注的文档
- [文学研究]07_基因组浏览器.pdf
- [文学研究]110519班组长培训讲义123.ppt
- [文学研究]2012年自考“美学”复习笔记超完整.doc
- [文学研究]2012高考英语第一轮复习 第一部分课文 Module 5 Unit 5 First aid课件.ppt
- [文学研究]2012届高考一轮复习英语课件:Unit 19《Language》北师大版选修7.ppt
- [文学研究]2第一章行政公文概述.ppt
- [文学研究]300种围巾系法.doc
- [文学研究]3社会语言学的基本概念.ppt
- [文学研究]4电子商务安全技术.ppt
- [文学研究]2012高考语文复习课件:语言表达综合题型举例.ppt
文档评论(0)