Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how to delete last node of a Linked list if you only know the address of last node.

Reply
Thread Tools

how to delete last node of a Linked list if you only know the address of last node.

 
 
sangram
Guest
Posts: n/a
 
      12-01-2006
how to delete last node of a Linked list if you only know the address
of last node.

thanks
sangram

 
Reply With Quote
 
 
 
 
ramasubramanian.rahul@gmail.com
Guest
Posts: n/a
 
      12-01-2006
hi
start traversing the node
see if the nodes it points to has the same address as the one you have
if it isnt then goto the next node and continue this process
if u find the address:
1> set the prev node's( where u are right now) next parameter to null
before go to the next node and make a copy..
after that do step no 1 and free the copied node.
sangram wrote:
> how to delete last node of a Linked list if you only know the address
> of last node.
>
> thanks
> sangram


 
Reply With Quote
 
 
 
 
sangram
Guest
Posts: n/a
 
      12-01-2006
hi friend,

its ok if u know the start of the node.

but only you know the end node and now u delete it.

thanks for comunication.
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> hi
> start traversing the node
> see if the nodes it points to has the same address as the one you have
> if it isnt then goto the next node and continue this process
> if u find the address:
> 1> set the prev node's( where u are right now) next parameter to null
> before go to the next node and make a copy..
> after that do step no 1 and free the copied node.
> sangram wrote:
> > how to delete last node of a Linked list if you only know the address
> > of last node.
> >
> > thanks
> > sangram


 
Reply With Quote
 
MQ
Guest
Posts: n/a
 
      12-01-2006

sangram wrote:
> how to delete last node of a Linked list if you only know the address
> of last node.


You can't, because you would need to know the address of the previous
node in order to be able to set its "next" pointer to null. If you
want to be able to remove any arbitrary node without needing to know
the address of any other node, then you will need to implement a
doubly-linked list. That is, each node will have a "next" and
"previous" pointer.

MQ

 
Reply With Quote
 
raxitsheth2000@yahoo.co.in
Guest
Posts: n/a
 
      12-01-2006
Try this out.

1. Make sure the address you are having is of Last Node.
2. Update it to Null
3. Free the memory
or step 3 and then step 2 depend on ur algo.

--raxit

sangram wrote:
> how to delete last node of a Linked list if you only know the address
> of last node.
>
> thanks
> sangram


 
Reply With Quote
 
Simon Biber
Guest
Posts: n/a
 
      12-01-2006
sangram wrote:
> how to delete last node of a Linked list if you only know the address
> of last node.


The answer to your question is to make it a doubly-linked list, then use
code like this:

if(last->prev)
{
last->prev->next = NULL;
last->prev = NULL;
}

If it's a singly-linked list then you're out of luck without access to
either the address of the first node or the address of the node before
the last.

--
Simon.
 
Reply With Quote
 
jaysome
Guest
Posts: n/a
 
      12-01-2006
On 30 Nov 2006 21:53:04 -0800, "sangram" <(E-Mail Removed)>
wrote:

>how to delete last node of a Linked list if you only know the address
>of last node.


In the real world:

Tell the interviewer that if he or she ever requires you to do such a
thing, then you don't want to ever work for him or her.

On your way running out the door, ask them what is the return type of
main(). If their response seems suspect--which is highly
probable--keep running, and consider yourself fortunate.

--
jay
 
Reply With Quote
 
Chris Dollin
Guest
Posts: n/a
 
      12-01-2006
sangram wrote:

> how to delete last node of a Linked list if you only know the address
> of last node.


This isn't a C question. comp.programming would be better.

(The answer, from the information given, is "you can't", but if you'd
like to show us the actual C code with the problem, maybe that will
speak more exactly about it.)

--
Chris "subtle, like a barrel" Dollin
"I'm still here and I'm holding the answers" - Karnataka, /Love and Affection/

 
Reply With Quote
 
mark_bluemel@pobox.com
Guest
Posts: n/a
 
      12-01-2006

sangram wrote:
> how to delete last node of a Linked list if you only know the address
> of last node.


If we are talking about a singly-linked list, I don't see how you
expect to do anything with it if you only know the address of the last
node... It's not really a linked list, in my mind, if you haven't got a
start point from which to start traversing...

Is this another homework or interview question? Can we have more
context please?

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      12-01-2006
sangram said:

> how to delete last node of a Linked list if you only know the address
> of last node.


exit(0); will do it. Don't forget <stdlib.h>, though.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Given only a pointer to a node to be deleted in a singly linked list, how do u delete it? ac.c.2k7@gmail.com C Programming 10 04-16-2007 06:36 AM
Given only a pointer to a node to be deleted in a singly linked list, how do u delete it? ac.c.2k7@gmail.com C++ 10 04-16-2007 06:36 AM
Delete node from singly linked list when header is not known Raj C++ 13 02-02-2006 06:21 AM
How to delete the node at the end (tail) of the Linked List ? Sumika C Programming 4 07-15-2005 07:14 AM



Advertisments