Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-27-2005, 09:07 AM   #1
Registered: Sep 2005
Location: kannur
Posts: 59

Rep: Reputation: 15
c++ help

hai sir

i have doubt on singly linked list operations.

in the case of deletion of a node from list,there are 3 case

delete from the front

delete from the end

delete from any location

what is C++ code for case2(deleting from end) and case3 deleting from any location)

please help me
Old 09-27-2005, 09:44 AM   #2
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
I'm not going to write the code for you, but I'll try and explain it.

I think of delete from end and delete from middle as being the same basic operation.

Point a temporary pointer at the element you want to delete. Modify the pointer of the element before it to point to the next pointer on the element you want to delete.


So if we want to delete d we set temp = d and set c = d->next (which is null in this case, but could easily be an element). Then you can simply delete d.

That make sense?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:48 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration