 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Aditya Guest
|
Posted: Wed Dec 20, 2006 10:10 am Post subject: Delete every mth element in a linked list ?? |
|
|
This is a normal interview question, which goes like this
"Given a linked list of integers, delete every mth node and return the
last remaining node."
eg: Linked list = 4->6->7->3->5->6->10->1->23->17
Delete every 3rd node (m = 3) and return the last remaining node
meaning...
4->6->3->5->10->1->17
4->3->5->1->17
3->5->17
3->17
3
after deleting every 3rd node the last remaining node is 3, so node
with data 3 is returned.
function prototype:
node* deleteEveryMth(node** head, int m)
{
// .... your code
}
thanks
A |
|
| Back to top |
|
 |
Alf P. Steinbach Guest
|
Posted: Wed Dec 20, 2006 10:10 am Post subject: Re: Delete every mth element in a linked list ?? |
|
|
* Aditya:
| Quote: | This is a normal interview question, which goes like this
"Given a linked list of integers, delete every mth node and return the
last remaining node."
eg: Linked list = 4->6->7->3->5->6->10->1->23->17
Delete every 3rd node (m = 3) and return the last remaining node
meaning...
4->6->3->5->10->1->17
4->3->5->1->17
3->5->17
3->17
3
after deleting every 3rd node the last remaining node is 3, so node
with data 3 is returned.
function prototype:
node* deleteEveryMth(node** head, int m)
{
// .... your code
}
|
Although the article quoted above is off-topic, it's interesting that
there's seemingly no consistent system in the example, and an
underspecified and at the same time overspecified example to be filled
out. With a meaningless argument. Are you sure this was all part of
the homework problem, or is it your elaboration?
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|