“Write a user-defined data type c++ implimentaion that is known as single link l
ID: 1922240 • Letter: #
Question
“Write a user-defined data type c++ implimentaion that is known as single link list linear having dynamic memory”.Explanation / Answer
#include …………… …………… …………… …………… struct NODE { int value; struct NODE*next; }; struct NODE*Head; struct NODE*Tail; void create list() { Head=NULL; Tail=NULL; } Void InsertNode( ) { struct NODE *temp; temp=(struct NODE*)malloc(size of NODE); if (head==NULL) head=temp; else tail-->next=temp; tail=temp; tail-->value=n; tail-->next=NULL; } void Traversal() { struct NODE*drag; drag=head; while (drag!=NULL) { coutnext; } } int search Node(int n) { struct NODE *drag; drag=Head; while(drag) { if (drag-->value==n) return1; else drag=drag-->next; } return 0; } int search and Delete(int n) { struct NODE * crnt,*prnt; if (!head) or if (head==NULL) return 0; crnt=head; if(n==head-->value) { head=head-->next; free(crnt); if (head==NULL) tail=NULL; return 1; } while (crnt!=NUll)&&(n!=crnt-->value) { prnt=crnt; crnt=crnt-->next; } if (crnt==NULL) return 0; prnt-->next=crnt-->next; if(crnt==tail) tail=prnt; free (crnt); return 1; } Void main( ) { …………….. …………….. …………….. …………….. }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.