欢迎来到天天文库
浏览记录
ID:22229331
大小:79.00 KB
页数:34页
时间:2018-10-27
《Algorithm for Inserting a node in a linked list》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、----------专业最好文档,专业为你服务,急你所急,供你所需-------------文档下载最佳的地方MemoryAllocation:1.Static–thesize/spaceisallocatedaltogetherinonelocationinasequenceforthedatainadvanceandcannotbechangedonceallocated.Example:Array2.Dynamic-thesize/spaceisallocatedrandomlyfromanywhereint
2、hememoryforthedataasandwhenneededsoitcanbechangedeasily.Example:LinkedlistsTypesofLinkedLists:1.SinglyLinkedlists(SLL)–onlyonelinkfromonenodetoanother2.DoublyLinkedlists(DLL)–twolinksbetween2nodes3.CircularLinkedLists(CLL)–lastnodepointstothefirstnodeOperation
3、sthatcanbeperformedonaSinglyLinkedlist:1.Insert/Addanewnodeinthelista)inthebeginningofthelistb)attheendofthelistc)inbetween2nodesofthelist2.Delete/Removeanodefromthelista)fromthebeginningofthelistb)fromtheendofthelistc)frombetween2nodesofthelist3.Traverse(read
4、anddisplaythevalues)thenodesinthelistAlgorithmforInsertinganodeinanemptylist:(insertingthe1stnode)1.Start=null//thereisnonodeinthelist2.Createnewnode//allocatememoryforthedatatobeinserted3.newnode.data=data//storethevalueinthedatafieldofthenewnode4.start=newno
5、de//makestartpointtothefirstnode5.newnode.next=null//thereisnonodeafterthisnodeAlgorithmforInsertinganodeattheendofalistthatalreadyhasoneormorenodes:1.ifStartisnotNULL//thereisatleastonenodepresentinthelist2.current=start//createacopyofstartwhichisusedtolocate
6、thelastnodesothatwedon’tlosethefirstnode3.Repeatcurrent=current.nextuntil----------专业最好文档,专业为你服务,急你所急,供你所需-------------文档下载最佳的地方----------专业最好文档,专业为你服务,急你所急,供你所需-------------文档下载最佳的地方current.next=null//(thepointerismovedfromonenodetoanotherinordertofindthelast
7、node)1.current.next=newnode//insertthenewnodeafterthelastnode2.newnode.next=null//newnodeisthelastnode----------专业最好文档,专业为你服务,急你所急,供你所需-------------文档下载最佳的地方----------专业最好文档,专业为你服务,急你所急,供你所需-------------文档下载最佳的地方AlgorithmforInsertinganodeinanemptylistusingLAST
8、:(insertingthe1stnode)1.start=nulllast=null//thereisnonodeorthelistdoesnotexist2.createnewnode3.newnode.data=data4.start=newnode5.last=newnode//newnodeistheonlynodeinthelistsoitist
此文档下载收益归作者所有