Jagged array - Wikipedia

文章推薦指數: 80 %
投票人數:10人

In computer science, a jagged array, also known as a ragged array, is an array of arrays of which the member arrays can be of different lengths, ... Jaggedarray FromWikipedia,thefreeencyclopedia Jumptonavigation Jumptosearch Memorylayoutofajaggedarray. Incomputerscience,ajaggedarray,alsoknownasaraggedarray[citationneeded],isanarrayofarraysofwhichthememberarrayscanbeofdifferentlengths,[1]producingrowsofjaggededgeswhenvisualizedasoutput.Incontrast,two-dimensionalarraysarealwaysrectangular[2]sojaggedarraysshouldnotbeconfusedwithmultidimensionalarrays,buttheformerisoftenusedtoemulatethelatter. ArraysofarraysinlanguagessuchasJava,PHP,Python(multidimensionallists),Ruby,C#.Net,VisualBasic.NET,Perl,JavaScript,Objective-C,Swift,andAtlasAutocodeareimplementedasIliffevectors. Examples[edit] InC#andJava[3]jaggedarrayscanbecreatedwiththefollowingcode:[4] int[][]c; c=newint[2][];//creates2rows c[0]=newint[5];//5columnsforrow0 c[1]=newint[3];//create3columnsforrow1 InCandC++,ajaggedarraycanbecreated(onthestack)usingthefollowingcode: intjagged_row0[]={0,1}; intjagged_row1[]={1,2,3}; int*jagged[]={jagged_row0,jagged_row1}; InC/C++,jaggedarrayscanalsobecreated(ontheheap)withanarrayofpointers: int*jagged[5]; jagged[0]=malloc(sizeof(int)*10); jagged[1]=malloc(sizeof(int)*3); InC++/CLI,jaggedarraycanbecreatedwiththecode:[5] usingnamespaceSystem; intmain() { array^>^Arrayname=gcnewarray^>(4);//arraycontains4 //elements return0; } InFortran,ajaggedarraycanbecreatedusingderivedtypeswithallocatablecomponent(s): type::Jagged_type integer,allocatable::row(:) endtypeJagged_type type(Jagged_type)::Jagged(3) Jagged(1)%row=[1] Jagged(2)%row=[1,2] Jagged(3)%row=[1,2,3] InPython,jaggedarraysarenotnativebutonecanuselistcomprehensionstocreateamulti-dimensionallistwhichsupportsanydimensionalmatrix:[6] multi_list_3d=[[[]foriinrange(3)]foriinrange(3)] #Produces:[[[],[],[]],[[],[],[]],[[],[],[]]] multi_list_5d=[[[]foriinrange(5)]foriinrange(5)] #Produces:[[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]]] Seealso[edit] Variable-lengtharray Iliffevector References[edit] ^JesseLiberty;BrianMacDonald(18November2008).LearningC#3.0."O'ReillyMedia,Inc.".pp. 210–.ISBN 978-0-596-55420-0. ^DonBox(2002).Essential.Net:TheCommonLanguageRuntime.Addison-WesleyProfessional.p. 138.ISBN 978-0-201-73411-9. ^"JaggedArrayinJava-GeeksforGeeks".GeeksforGeeks.2016-02-03.Retrieved2018-08-13. ^PaulJ.Deitel;HarveyM.Deitel(26September2008).C#2008forProgrammers.PearsonEducation.p. 40.ISBN 978-0-13-701188-9. ^"JaggedArrays".FunctionX.Retrieved26November2014. ^"ListsinPythonDemystified".Alvin.io.Retrieved31January2016. Thiscomputersciencearticleisastub.YoucanhelpWikipediabyexpandingit.vte Retrievedfrom"https://en.wikipedia.org/w/index.php?title=Jagged_array&oldid=1076413658" Categories:ArraysComputersciencestubsHiddencategories:AllarticleswithunsourcedstatementsArticleswithunsourcedstatementsfromMarch2022ArticleswithexamplePython(programminglanguage)codeAllstubarticles Navigationmenu Personaltools NotloggedinTalkContributionsCreateaccountLogin Namespaces ArticleTalk English Views ReadEditViewhistory More Search Navigation MainpageContentsCurrenteventsRandomarticleAboutWikipediaContactusDonate Contribute HelpLearntoeditCommunityportalRecentchangesUploadfile Tools WhatlinkshereRelatedchangesUploadfileSpecialpagesPermanentlinkPageinformationCitethispageWikidataitem Print/export DownloadasPDFPrintableversion Languages БългарскиItalianoעברית Editlinks



請為這篇文章評分?