資源描述:
《arrays - home university of calgary陣列-家居卡爾加里大學(xué)》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在應(yīng)用文檔-天天文庫。
1、ARRAYSArraysareusuallyafeaturefoundinmanyprogramminglanguages.Thesearecombinationsofsimpletypesfoundinthelanguageandarecalledstructuredtypes.Theyarereallyaspecialtypeofdatastructurewhichhassomeabstractionsbuiltintothelanguagethatallowtheusertousethestructureeasily.ArraysarealsoanAbstractDataTypeandc
2、anbedefinedbytheprocesseswhichmakeupthestructure.Theseare:1.Create:Allocatethespacerequiredforstoringthearray.2.Insert:Insertvaluesintospecifiedelementsofthearray.3.Retrieve:Obtainvaluesforspecifiedelementsofthearray.Whenarraysarestored,theyaregenerallycontiguousinmemory,thatis,oneelementfollowsdire
3、ctlyaftertheotherinonelargeblockofmemory.Thesystemgenerallystoresthenameofthearray,thepointinmemorywherethearraybegins,thenumberofelementsinthearray,andthesizeofeachelement.Thesizeoftheelementisdeterminedbyanalyzingthetypeoftheelementwhichcanbequitesimpleorvaryincomplexity.Fromauser’spointofview,all
4、thatisrequiredistospecifythenameofthearrayandtheelementnumber.Elementsareusuallynumberedbeginningat0andaresaidtobezero-indexed.Thestructure’sdesignissuchthattheuserdoesnotneedtoknowhowtogettothelocationrequested,thisisdonebythesystem.MappingFunctionsOne-dimensionalarraysThemappingfunctionisusedbythe
5、systemtofindthebeginningofthespecifiedarrayelement.Supposethatwehaveanarrayof4elementscalled‘one’.WecanpicturethisasThesystemwillknowitsname,thebeginningpointinmemoryandthenumberofelements.However,findinganyelementwilldependonhowfaritmovesdownthischunkofmemory,sothesizeofeachelementmustbeknownandisd
6、eterminedbythetypedeclarationwhenthearrayisdeclared.Ifthearrayabovestorescharacters,then1byteisrequiredforeachelement.Ifweweretostorelongs,8byteswouldberequiredforeachelement.Inordertomakesurethesystemislookingatthebeginningofthebyterequested,itusesamappingfunction.Ingeneral,themappingfunctionwouldb
7、eposition=start+(sizeofelement*numberofelement)Thus,ifthearraycontainslongs,thenfindingthestartofelement#2wouldbePosition=start+(8*2)or16bytesbeyondthestartposition.Notethatthisisthebeginningofelement