10.09.2013 Views

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

LECTURE NOTES OF ADVANCED DATA STRUCTURE (MT-CSE 110)<br />

DELETING FROM THE END OF THE LIST<br />

To delete anelement from the end of the list, we first traverse to the second last<br />

element of the list and follow the given below algorithm<br />

Algorithm<br />

Deleting (START).This algorithm deletes an element from the last position of the<br />

linked list.<br />

<strong>1.</strong> [Check for underflow ?]<br />

if start = NULL , then<br />

print, ‘Linked list empty’<br />

Exit<br />

End if<br />

2. If start next = NULL, then<br />

Set PTR=start<br />

Set start = NULL<br />

Print, element deleted is = PTR INFO<br />

Free(PTR)<br />

END if<br />

3.Set PTR =START<br />

4. Repeat steps 5 and 6 will PTNext!=NULL<br />

5. Set LOC = PTR<br />

6. Set PTR = PTNext<br />

7. Set LOCnext = NULL<br />

8.Free( PTR)<br />

DELETION AFTER A GIVEN ELEMENT OF THE LIST<br />

To delete an element after a given element, first we find the location(say loc) of<br />

the element after which the element to be deleted comes.<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

Assist Prof., CSE, H.C.T.M (Kaithal) Page ‐ 110 ‐

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!