Tuesday, June 4, 2019

Project Assignment On Doubly And Circular Linked Lists Engineering Essay

Project Assignment On Doubly And Circular conjugated Lists Engineering adjudicateAs a computer engineer I would like to deal with this topic following a step by step approach. Before divergence into the de female genital organs and the programs of twice and circular link leans we need to concentrate upon the meaning of the term cerebrate incline.The meaning of the terminology link list can but be dealed by dividing it into chunks .In a laymans term a link list is a logical collection of data stored in a systems memory in which every record that is the part of the given list has a pointer or link part that contains the address of the next record .This is how it worksLinked lists are used to organize data in specific desired logical orders, independent of the memory address each record is assigned to. startly, we would contend linked lists in the terms of singly linked lists or what we call as SLLs .SLLs can be thought to be non-contiguous block of memory consisting of exhau stible number of lymph glands with the address of the successor lymph leaf thickening stored in the link part of the preceding node. Each node has a DATA part and a tie in part. DATA PART STORES THE ACTUAL DATA ELEMENT WHILE THE LINK PART CONTAINS THE ADRESS OF THE NEXT inspissation i.e. THE ONE JUST AFTER THAT NODE omit FOR THE LAST NODE THAT DOESNT POINT TO ANYTHING OR WE CAN SAY zero.This is depicted in the following diagram-But to beginners this may sound confusing that if unmatchable node stores the address of the next node then where is the address of the first node stored?However this question isnt a big deal .To counter this line we allocate memory for a dummy node that volition store the address of the first node .This mind or the dummy node has just the link part (and not the data part).This node is always supposed to point to the first node of the list.OPERATIONS POSSIBLE WITH SLLsCREATE CREATING THE LIST FOR THE number 1 TIME.INSERT INSERTING AN ELEMENT TO T HE EXISTING LIST.DELETE DELETING AN ELEMENT FROM THE EXISTING LIST.SEARCH 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 linked list the programs on SLLs wont be discussed in detail. Only program on creating a SLL is included -THIS IS SIMPLE FUNCTION IN C++ DEPICTING HOW TO CREATE A SINGLY LINKED LISTSTRUCT nodeT INT datanodeT* link nodeT* BUILD() nodeT *first= zip,* refreshful nodeINT numCOUTCINnumWHILE(num =178) New node = refreshed nodeT // make water a nodeASSERT ( unexampled node =NULL) //program end if memory not allocatedNew node - data =num //stores the data in the clean nodeNew node -link =first //put new node at the start of listFirst= new node //update the dummy pointer of the listCinnum //read the next numberRETURN first// this program is also called building list from backwards ITS OUTPUT CAN BE SEEN AS IN BELOW BLOCK DIAGRAMCUsers the PANKESHAppDataLocalMicrosoftWindowsTemporary Internet FilesContent.IE57OPVY3E3MCj019784700001.wmfAs we deport discussed earlier that linked lists are such data structures 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 parts unity to store the address of the succeeding node and the other for the preceding node. This makes doubly linked lists bidirectional i.e. they can be traversed in either direction, forward or backward. This is sh bear 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 space per node as two pointers will be needed but their advantage of sequential access in either direction make its manipulation quite easier which overcome its former shortcoming.CUsersthe PANKESHAppDataLocalMicrosoftWindowsTemporary Internet FilesContent.IE57OPVY3E3MPj044243000001.jpgOPERATIONS DONE ON do ubly LINKED LISTS ARE ALMOST THE SAME AS THAT ON SLLs BUT HAVE BEEN DISCUSSED IN position HERE CREATING AN EMPTY LIST ADDING A NODE AT THE END ADDING A NODE IN THE extraction DELETING A NODE IN THE BEGINNING DELETING A NODE AT THE END FORWARD TRAVERSAL REVERSE TRAVERSAL INSERTING A NODE AT A SPECIFIC PLACE DELETING A LISTMISCELLENEOUSUSE OF CONSTRUCTORS IN DOUBLY LINKED LISTSIF THE LINKED LIST IS MADE USING CLASSES INSTEAD OF STRUCTURES THEN DEFAULT CONSTRUCTORS CAN BE use TO INITIALISE THE WHOLE LIST TO A PARTICULAR VALUEEG IT SETS FIRST AND LAST TO NULL AND COUNT TO 0.SYNTAXTemplateDoubly_linked_listdoubly_linked_list() first=null get going=nullCount=0 FOLLOWING IS A C++ PROGRAM DEPICTING ALL THE OPERATIONS MENTIONED ABOVE THAT CAN BE PERFORMED USING DOUBLY LINKED LISTSinclude // header files in c++includetypedef struct doubly //self referential structure for making a linked list int datastruct doubly*frwd //frwd and back are the two pointers of the linked liststruct doubly*ba ck node //node is a global object stave off create empty (node**frwd,node**back) //create empty is to set the pointers to null*frwd=*back=NULLvoid 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 delete_at_beg(node**frwd,node**back) // delete_at_beg is to delete a node in the startnode*ptrif(*frwd==(node*)NULL)return()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*search(node*frwd,int item) //search is to search a given element in the list while(=(node*)NULL frwd-info=item)frwd=frwd-frwdreturn frwd // insert-after-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) example 1coutcinelementadd_at_end(frwd,back,element)getch()breakcase 2coutcinelementadd_at_beg(frwd,back,element)breakcase 3in ordertrav(frwd)getch()breakcase 4reverse-order-trav(back)getch()breakcase 5coutcinaftercoutcinelementinsert-after-node(frwd,back,element,after)breakcase 6coutcinaftercoutcinelementinsert-before-node(frwd,element,aft er)breakcase 7delete-at-beg(frwd,back)breakcase 8delete-at-end(frwd,back)breakcase 9delete-list(frwd,back)breakcase 10exit()SOME INTERESTING FACTS -One byte meat 8 bits and a nibble means 4 bits.First hard disk available 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 traffic rate.An average American is dependent on 250 computers.Internet is most fastest growing platform for advertisement.About one trinity of CDs are piratedAbout 76% soft wares used in India are pirated.Only 10% of the WebPages are used by the search enginesI olfactory property Lucky 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 naturally circular ,e.g. in this a pointer to any node serves as a handle to the whole list.With a circular list, a pointer to the start node gives easy access also to the first node ,by following one link. Using circular lists one has access to both ends of the list. A circular structure allows one to handle the structure by a single pointer, kind of 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 constant 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 ability 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. See following type-FOLLOWING PROGRAM DEPICTS THE USE OF DOUBLY LINKED CIRCULAR LISTincludeincludeclass C_link //DEFINING A CLASS THATstruct node // ego REFERENTIAL STRUCTURE nodeint datanode *frwdnode *back*new1,*head,*tail,*ptr,*temp //GLOBAL OBJECTS REQUIRED FOR OPERATIONSpublicC_link()head=tail=NULLvoid CREATE() //CREATE() ,INSERT(), DELETE(), DISPLAYING() are the various functionsvoid INSERT() //that we operate using circular linked listsvoid DELETE()void DISPLAYING()void C_link CREATE() //defining the CREATE() function 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=ne w 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 ptrelsehead=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)co utdatabreakcase 2 if(tail=NULL)temp=tailwhile(temp=head)coutdatatemp=temp-backif(temp==head)coutdatabreakmain()C_link c1int ch blacken opdocoutcoutcout ?cinchswitch(ch)case 1 c1.CREATE()breakcase 2 c1.INSERT()breakcase 3 c1.DELETE()breakcase 4 c1.DISPLAYING()breakcout ? //while entwine 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 option 1 and entering 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 ASSIGNMENT PURELY DESCRIBES HOW DOUBLY AND CIRCULAR LISTS CAN BE employ .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 si gnificant KIND OF DATA STRUCTURE.IT CAN BE USED TO IMPLEMENT BOTH STACKS AND QUEUES ALSO WHICH WE WILL STUDY ON LATER PART.THANKS.

No comments:

Post a Comment