资源描述:
《数据结构与算法分析 C语言描述(第2版)Larry Nyhoff 抽象数据类型 课件.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、DataStructuresandAbstractDataTypesChapter31Nyhoff,ADTs,DataStructuresandProblemSolvingwithC++,SecondEdition,©2005PearsonEducation,Inc.Allrightsreserved.0-13-140909-3ChapterContents3.1DataStructures,AbstractDataTypesandImplementations3.2StaticArrays3.3MultidimensionalArrays(optional)3.4Dyna
2、micArrays3.5C-StyleStructs(optional)3.6ProceduralProgramming2Nyhoff,ADTs,DataStructuresandProblemSolvingwithC++,SecondEdition,©2005PearsonEducation,Inc.Allrightsreserved.0-13-140909-3ArraysCollectionofdataelementsAllofsametypeEachaccessedbyspecifyingpositionStaticarrayCompilerdetermineshow
3、memoryallocatedDynamicarrayAllocationtakesplaceatruntime3Nyhoff,ADTs,DataStructuresandProblemSolvingwithC++,SecondEdition,©2005PearsonEducation,Inc.Allrightsreserved.0-13-140909-3SingleDimensionArraysSyntax:ElementTypearrayName[CAPACITY];ElementTypearrayName[CAPACITY]={initializer_list};
4、Example:intb[10];Elementsaccessedbynameand[]operationb[5]4Nyhoff,ADTs,DataStructuresandProblemSolvingwithC++,SecondEdition,©2005PearsonEducation,Inc.Allrightsreserved.0-13-140909-3CharacterArraysElementsofanarraymaybeofanytypeIncludingcharactersExample:charname[NAME_CAPACITY]="JohnDoe";If
5、arrayinitializedshorterthanspecsextralocationsfilledwithnullcharacter5Nyhoff,ADTs,DataStructuresandProblemSolvingwithC++,SecondEdition,©2005PearsonEducation,Inc.Allrightsreserved.0-13-140909-3SubscriptOperationWehavesaidelementsaccessedbynameand[]numList[5]Considerthe[]tobeanoperatorThesub
6、scriptoperatorPerformsaddresstranslationNameofthearrayisapointerconstantThebaseaddress6Nyhoff,ADTs,DataStructuresandProblemSolvingwithC++,SecondEdition,©2005PearsonEducation,Inc.Allrightsreserved.0-13-140909-3UsingArraysAccessingarrayforoutputSeeFig.3.3AccessingarrayforinputfromkeyboardSee
7、Fig.3.4NoteuseofarraysasparametersMustspecifynumberofelementsofarraybeingused7Nyhoff,ADTs,DataStructuresandProblemSolvingwithC++,SecondEdition,©2005PearsonEducation,Inc.Allrightsreserved.0-13-140909-3OutofRangeErrorsMostC++compilersdonotbydefaultcheckindicesfo