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 />

INSERTING AT THE BEGINNING OF THE LIST<br />

To insert an element at the beginning of the list,first we test whether the linked<br />

list is initially empty .If yes, then the element is inserted as the first and only<br />

element of the list<br />

However, if the list is initially not empty, then the element is inserted as the<br />

first element of the list<br />

Algorithm<br />

INSERT_FIRST(START ITEM).This algo insert an item as the first Node of the<br />

Linked list pointed by start<br />

<strong>1.</strong> [check for overflow ?]<br />

if PTR=NULL, then<br />

print,overflow<br />

exit<br />

else<br />

PTR=(Node *) malloc(size of (node)).<br />

//Create new node from memory and assign its<br />

address to PTR<br />

End if<br />

2. Set PTR INFO=item<br />

3. Set PTRNEXT=START<br />

4. Set START=PTR<br />

INSERTING A NODE AT THE END<br />

To insert the element at the end of the list, first we test whether the linked list<br />

is initially empty.If yes, then the element is inserted as the first and and only<br />

element of the list<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

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

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

Saved successfully!

Ooh no, something went wrong!