linklist

S

senthil

1) Is there a way, to delete say "n"th node in a link list without
actually traversing?

2) Is there a way to find out the number of nodes in the list without
traversing?
 
D

dandelion

Assuming we're talking of a 'standard' linked list.
1) Is there a way, to delete say "n"th node in a link list without
actually traversing?
No.

2) Is there a way to find out the number of nodes in the list without
traversing?

No.

Unless you have trouble with an implementation in C, and it's a 'C' issue
(instead of some library or the OS) this is off topic.
 
I

infobahn

senthil said:
1) Is there a way, to delete say "n"th node in a link list without
actually traversing?

No, unless you happen to know it's the first, or perhaps last, item
in the list. Ask your programming tutor for details.

2) Is there a way to find out the number of nodes in the list without
traversing?

Yes. Again, ask your programming tutor for details.
 
O

osmium

senthil said:
2) Is there a way to find out the number of nodes in the list without
traversing?

I'm sure you realize that you could tally items as you add and remove items
from the list?
 
S

senthil

infobahn said:
No, unless you happen to know it's the first, or perhaps last, item
in the list. Ask your programming tutor for details.



Yes. Again, ask your programming tutor for details.

If my programming tutor knows it, i would not have asked for it in
this newsgroup, wasting u people's precious time.
Please let me know "How to find out the number of nodes in the list
without traversing ?", I ask again, because you said,"Yes."
 
R

Richard Bos

senthil said:
If my programming tutor knows it, i would not have asked for it in
this newsgroup, wasting u people's precious time.
Please let me know "How to find out the number of nodes in the list
without traversing ?", I ask again, because you said,"Yes."

You do not get infobahn's point, I'm afraid. Let me state it more
clearly, then: Do Your Own Damn Homework.

Richard
 
M

Mike Wahler

senthil said:
If my programming tutor knows it, i would not have asked for it in
this newsgroup, wasting u people's precious time.
Please let me know "How to find out the number of nodes in the list
without traversing ?", I ask again, because you said,"Yes."

If you just take a moment to put yourself in the computer's
shoes, the answer should become obvious.

-Mike
 
G

gooch

If my programming tutor knows it, i would not have asked for it in
this newsgroup, wasting u people's precious time.
Please let me know "How to find out the number of nodes in the list
without traversing ?", I ask again, because you said,"Yes."
The question was already answered. Take the time to read the responses.
 
T

The Dragon

If my programming tutor knows it, i would not have asked for it in
this newsgroup, wasting u people's precious time.
Please let me know "How to find out the number of nodes in the list
without traversing ?", I ask again, because you said,"Yes."
The question was already answered. Take the time to read the responses.

I don't know of any way to do it without traversing the list, however, you
could actually keep count of inserted and deleted nodes. The count would
get out of whack if you have a bad algorithm for insertion, or deletion, and
end up with orphan nodes, but this would certainly suffice, infact, its
quite possible to keep a count in the head of the list and leave that
variable unused in the rest of the nodes, although thats wasteful
(sizeof(int) * # nodes - sizeof(int) wasteful to be exact.)

-- The Dragon
MHM 7x9, Hits you harder than a 2x4.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top