資源描述:
《Algorithm for Inserting a node in a linked list》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫(kù)。
1、----------專業(yè)最好文檔,專業(yè)為你服務(wù),急你所急,供你所需-------------文檔下載最佳的地方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----------專業(yè)最好文檔,專業(yè)為你服務(wù),急你所急,供你所需-------------文檔下載最佳的地方----------專業(yè)最好文檔,專業(yè)為你服務(wù),急你所急,供你所需-------------文檔下載最佳的地方current.next=null//(thepointerismovedfromonenodetoanotherinordertofindthelast
7、node)1.current.next=newnode//insertthenewnodeafterthelastnode2.newnode.next=null//newnodeisthelastnode----------專業(yè)最好文檔,專業(yè)為你服務(wù),急你所急,供你所需-------------文檔下載最佳的地方----------專業(yè)最好文檔,專業(yè)為你服務(wù),急你所急,供你所需-------------文檔下載最佳的地方AlgorithmforInsertinganodeinanemptylistusingLAST
8、:(insertingthe1stnode)1.start=nulllast=null//thereisnonodeorthelistdoesnotexist2.createnewnode3.newnode.data=data4.start=newnode5.last=newnode//newnodeistheonlynodeinthelistsoitist