Tuesday, April 2, 2019
Project Assignment On Doubly And Circular Linked Lists Engineering Essay
Project Assignment On Doubly And Circular connect Lists Engineering EssayAs a computer engineer I would like to deal with this topic following a step by step approach. Before going into the de tin cans and the broadcasts of doubly and circular cerebrate leans we need to concentrate upon the meaning of the term refered list.The meaning of the voice communication have-to doe with list fecal matter further be dealed by dividing it into chunks .In a laymans term a crosstie list is a crystal clear sight of selective information stored in a systems storehouse in which every go in that is the dismantle of the precondition list has a academic degreeer or link part that contains the address of the future(a) record .This is how it worksLinked lists are used to organize entropy in specific desired logical orders, indep obliterateent of the repositing address each record is assigned to.Firstly, we would demonstrate united lists in the terms of individually think lists or wh at we call out as SLLs .SLLs can be thought to be non-contiguous block of memory consisting of finite consequence of invitees with the address of the successor lymph gland stored in the link part of the antecede customer. Each client has a DATA part and a LINK part. DATA PART STORES THE ACTUAL DATA divisor WHILE THE LINK PART CONTAINS THE ADRESS OF THE NEXT NODE i.e. THE ONE honest AFTER THAT NODE EXCEPT FOR THE LAST NODE THAT DOESNT POINT TO ANYTHING OR WE fundament SAY NULL.This is depicted in the following diagram- however to beginners this may sound confusing that if one boss stores the address of the next pommel then where is the address of the initiatory node stored?However this wonder isnt a big deal .To counter this problem we allocate memory for a dummy node that will store the address of the first node .This corresponder point or the dummy node has only the link part (and not the data part).This node is always supposed to point to the first node of the list. trading operations POSSIBLE WITH SLLsCREATE CREATING THE LIST FOR THE front TIME.INSERT INSERTING AN ELEMENT TO THE EXISTING LIST.DELETE DELETING AN ELEMENT FROM THE EXISTING LIST. count SEARCHING AN ELEMENT FROM THE EXISTING LIST.REMEMBER SLLs CAN BE TRAVERSED UNIDIRECTIONALLY scarcely i.e. ONLY IN FORWARD DIRECTION.Since this assignment deals with doubly and circular conjugate list the programs on SLLs wont be discussed in de get across. Only program on creating a SLL is included -THIS IS SIMPLE FUNCTION IN C++ DEPICTING HOW TO CREATE A SINGLY conjugate LISTSTRUCT nodeT INT datanodeT* link nodeT* BUILD() nodeT *first=NULL,* impudently nodeINT numCOUTCINnumWHILE(num =178) New node = forward-looking nodeT //create a nodeASSERT ( sore node =NULL) //program end if memory not allocatedNew node - data =num //stores the data in the saucily nodeNew node -link =first //put new node at the start of listFirst= new node //update the dummy arrow of the listCinnum //read the next number RETURN first// this program is also called building list from rearward ITS OUTPUT CAN BE SEEN AS IN BELOW obstruction DIAGRAMCUsersthe PANKESHAppDataLocalMicrosoftWindowsTemporary Internet FilesContent.IE57OPVY3E3MCj019784700001.wmfAs we have discussed earlier that linked lists are such data expressions that contain linked nodes each containing a DATA part and a LINK part. But contrary to SLLs, in doubly linked lists each node has two link part one to store the address of the succeeding node and the other for the preceding node. This sterilises doubly linked lists bidirectional i.e. they can be traversed in all direction, forward or spinal columnward. This is shown in the following diagram-NODE 3 NODE 2 NODE 1But there is a disadvantage to the use of doubly linked lists also, that is it requires more of memory length per node as two pointers will be needed merely their advantage of sequential access in either direction make its manipulation quite easier which overcome its f ormer shortcoming.CUsersthe PANKESHAppDataLocalMicrosoftWindowsTemporary Internet FilesContent.IE57OPVY3E3MPj044243000001.jpgoperations DONE ON in two ways think LISTS ARE ALMOST THE resembling AS THAT ON SLLs BUT HAVE BEEN DISCUSSED IN DETAIL here CREATING AN EMPTY LIST ADDING A NODE AT THE END ADDING A NODE IN THE get DELETING A NODE IN THE BEGINNING DELETING A NODE AT THE END FORWARD TRAVERSAL turnabout TRAVERSAL INSERTING A NODE AT A SPECIFIC inject DELETING A LISTMISCELLENEOUSUSE OF CONSTRUCTORS IN DOUBLY joined LISTSIF THE LINKED LIST IS MADE USING CLASSES INSTEAD OF STRUCTURES THEN DEFAULT CONSTRUCTORS CAN BE utilise TO INITIALISE THE WHOLE LIST TO A circumstance VALUEEG IT SETS FIRST AND LAST TO NULL AND COUNT TO 0.SYNTAX pathfinderDoubly_linked_listdoubly_linked_list() first=nullLast=nullCount=0 undermentioned IS A C++ PROGRAM DEPICTING ALL THE OPERATIONS MENTIONED to a higher place THAT CAN BE PERFORMED USING DOUBLY LINKED LISTSinclude // cope files in c++inc ludetypedef struct doubly //self referential structure for making a linked list int infostruct doubly*frwd //frwd and masking are the two pointers of the linked liststruct doubly* stomach node //node is a global object nullity create lift (node**frwd,node**back) //create empty is to set the pointers to null*frwd=*back=NULL vacuum add_at_end(node**frwd,node**back,int element) // add_at_end is to add a node in the endnode*ptrptr=new nodeptr-info=elementptr-frwd=NULLif(*frwd==NULL)ptr-back=NULL*frwd=ptr*back=ptrelseptr-back=*back(*back)-frwd=ptr*back=ptrvoid add_at_beg(node**frwd,node**back,int item) // add_at_beg is to add a node in the start node*ptrptr=new nodeptr-info=itemptr-back=(node*)NULLptr-frwd=*frwdif(*frwd==(node*)NULL*back=ptr*frwd=ptrvoid offset_at_beg(node**frwd,node**back) // delete_at_beg is to delete a node in the startnode*ptrif(*frwd==(node*)NULL) save()if((frwd))-frwd==(node*)NULL) ptr=*frwd*frwd=*back=(node*)NULLdelete(ptr) elseptr=*frwd*frwd=(*frwd-frwd(*frwd )-back=(node*)NULLdelete(ptr)void delete_at_end(node**frwd,node**back)) // delete_at_beg is to delete a node in the endnode*ptrif(*frwd==(node*)NULL)returnif((*frwd)-frwd==(node*)NULL) ptr=*frwd*frwd=*back=(node*)NULLdelete (ptr) else ptr=*back*back=ptr-back(*back)-frwd=(node*)NULLdelete(ptr)void inordertrav(node*)NULL // inordertrav is to traverse the list in the forward direction while(frwd=NULL) printf(%d,frwd-info)frwd=frwd-frwdvoid reverse ordertrav(node*back) // reverseordertrav is to traverse the list in the back direction while(back=node*)NULL) coutinfoback=back-backnode* seek(node*frwd,int item) //search is to search a given element in the list while(=(node*)NULL frwd-info=item)frwd=frwd-frwdreturn frwd // store- afterwards-node is to insert a node at a specified position after the provided nodevoid insert-after-node(node**frwd,node**frwd,int item,int after) node*loc,*ptrptr=new nodeptr-info=itemloc=*frwdloc=search(loc,after)if(loc==(node*)after)coutreturnelse if(loc-frwd ==(node*)NULL) ptr-frwd=(node*)NULLptr-frwd=ptr*frwd=ptr else ptr-frwd=loc-frwdptr-back=loc(loc-frwd)-pre=ptrloc-frwd=ptr // insert-before-node is to insert a node at a specified position before the provided nodevoid insert-before-node(node**frwd,int item,int before)node*ptr,*locptr=new nodeptr-info=itemloc=*frwdloc=search(loc,before)if(loc==(node*)NULL coutreturnelse if(loc-back==(node*)NULL)ptr-back=(node*)NULLloc-back=ptrptr-frwd=*frwd*frwd=ptr else ptr-back=loc-backptr-frwd=loc(loc-back)-frwd=ptrloc-back=ptrvoid delete-list(node**frwd**frwd) //delete-list is to destroy the created list node*ptrwhile(*frwd=(node*)NULL)ptr=*frwd*frwd=(*frwd)-frwd(*frwd)-back=(node*)NULLdelete(ptr) *frwd=(node*)NULLvoid main() node,*frwd,*frwdint ch,element,aftercreate_empty(frwd,back)while(1)coutcoutcoutcoutcoutcoutcoutcoutcoutcoutcoutcinchswitch(ch) grammatical fictional character 1coutcinelementadd_at_end(frwd,back,element)getch() calve moorage 2coutcinelementadd_at_beg(frwd,back,element)break case 3in ordertrav(frwd)getch()breakcase 4reverse-order-trav(back)getch()breakcase 5coutcinaftercoutcinelementinsert-after-node(frwd,back,element,after)breakcase 6coutcinaftercoutcinelementinsert-before-node(frwd,element,after)breakcase 7delete-at-beg(frwd,back)breakcase 8delete-at-end(frwd,back)breakcase 9delete-list(frwd,back)breakcase 10exit()SOME INTERESTING FACTS -One byte means 8 bits and a nibble means 4 bits.First hard disk ready(prenominal) was of 5MBEthernet is the registered trademark of Xerox.Google uses over 10000 network computers to crawl the webGoogle can be queried in 26 languagesThe floppy disk was patented by Allen sugar in 1946.More than 80% of web pages are in English.88% percent web pages have very low trade rate.An average American is dependent on 250 computers.Internet is most swift growing platform for advertisement. most one third of CDs are piratedAbout 76% soft wares used in India are pirated.Only 10% of the WebPages are used by the search enginesI fee ling favored This button is used by negligible number of people on net.CONTINUED..CIRCULAR LINKED LISTA circularly linked list is just like representing an array that are supposed to be by nature circular ,e.g. in this a pointer to every node serves as a handle to the whole list.With a circular list, a pointer to the last node gives easy access also to the first node ,by following one link. Using circular lists one has access to both(prenominal) ends of the list. A circular structure allows one to handle the structure by a single pointer, instead of two.Thus we see ,all nodes are linked in a continuous circle form without using any NULL pointer in the last node. Here the next node after the last node is the first node .Elements can be added to the back of the list and removed from the front in a everlasting period of time.We can classify circularly linked lists into two kinds- singly linked and doubly linked. Both types have advantage of its own .either of them has the faculty to traverse the full list beginning at any given node. this helps us to avoid storing any FIRSTnode LASTnode ,although if the list is empty there dwells a need of a special representation for the empty list, such as a LASTnode variable which points to some node in the list or is NULL if it is empty we use such a LASTnode here. This representation simplifies adding and removing nodes with a non-empty list, but empty lists are then a special case. essay following figure-FOLLOWING PROGRAM DEPICTS THE USE OF DOUBLY LINKED CIRCULAR LISTincludeincludeclass C_link //DEFINING A CLASS THATstruct node //SELF REFERENTIAL STRUCTURE nodeint datanode *frwdnode *back*new1,* drift,* female genitalia,*ptr,* temp //GLOBAL OBJECTS REQUIRED FOR OPERATIONSpublicC_link() signal=tail=NULLvoid CREATE() //CREATE() ,INSERT(), DELETE(), DISPLAYING() are the versatile snuff itsvoid INSERT() //that we operate using circular linked listsvoid DELETE()void DISPLAYING()void C_link CREATE() //defining the CREAT E() melt to create a listif(head==NULL)new1=new nodenew1-frwd=NULLnew1-back=NULLcoutcinnew1-datahead=new1tail=new1head-frwd=tailhead-back=tailtail-frwd=headtail-back=headelsecoutvoid C_link INSERT() //INSERT() function for inserting a new nodeint i,posnew1=new nodenew1-frwd=NULLnew1-back=NULLcoutcinnew1-datacoutcinposif(pos==1)new1-frwd=headhead=new1tail-back=headtail-frwd=headhead-back=tailelsei=1temp=headwhile(i frwd=tail)i++temp=temp-frwdif(temp-frwd==tail)new1-frwd=tail-frwdtail-frwd=new1new1-back=tailtail=new1head-back=tailelsenew1-frwd=temp-frwdnew1-back=temptemp-frwd=new1new1-frwd-back=new1void C_link DELETE() //DELETE() function for deleting a particular nodeint pos,icoutcinposif(pos==1 head=tail)ptr=headhead=head-frwdhead-back=tailtail-frwd=headdelete ptrelsei=1temp=headwhile(i frwd=tail)i++temp=temp-frwdif(temp-frwd=tail)ptr=temp-frwdtemp-frwd=ptr-frwdptr-frwd-back=ptr-backdelete ptrelseif(temp-frwd==tail head=tail)ptr=tailtail=temptail-frwd=headhead-back=taildelete pt relsehead=NULLtail=NULLdelete headdelete tailvoid C_linkDISPLAYING() // DISPLAYING() function is used to DISPLAYING the list in either directionint chcoutcoutcout?cinchswitch(ch)case 1 if(head=NULL)temp=headwhile(temp=tail)coutdatatemp=temp-frwdif(temp==tail)coutdatabreakcase 2 if(tail=NULL)temp=tailwhile(temp=head)coutdatatemp=temp-backif(temp==head)coutdatabreakmain()C_link c1int chchar opdocoutcoutcout ?cinchswitch(ch)case 1 c1.CREATE()breakcase 2 c1.INSERT()breakcase 3 c1.DELETE()breakcase 4 c1.DISPLAYING()breakcout ? //while loop In case the user want to continue usingcinop //the functions that are declared formerlywhile(op==y op==Y)getch()OUTPUT1.on pressing F9ass4.jpg2.on pressing survival of the fittest 1 and enter 09173now2.jpgContinued3.pressing y and selecting option 2 entering 09175 storing at pos 2now3.jpg4.pressing y and selecting option 3 enter pos 1now4.jpg5.pressing y and selecting option 4 and then 1ow6.jpgNote Number is 09175 9175CONCLUSIONTHIS identifi cation PURELY DESCRIBES HOW DOUBLY AND CIRCULAR LISTS CAN BE USED .WHERE DOUBLY USED TWO POITNTERS FOR THE SEQUENTIAL ACCESS OF THE NODES THE CIRCULAR LISTS MAY either BE SINGLY LINKED OR DOUBLY LINKED DEPENDING UPON HOW IT SUITS OUR PURPOSE.THIS MAKES LINKED LIST AN IMPORTANT KIND OF DATA STRUCTURE.IT CAN BE USED TO IMPLEMENT BOTH STACKS AND QUEUES ALSO WHICH WE WILL STUDY ON LATER PART.THANKS.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment