LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 09-27-2005, 08:07 AM   #1
sajith
Member
 
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, 08:44 AM   #2
jtshaw
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.

a->b->c->d->NULL

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?
 
  


Reply


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



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:57 PM.

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