删除链表中的每个第m个元素?? [英] Delete every mth element in a linked list ??

查看:83
本文介绍了删除链表中的每个第m个元素??的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个正常的面试问题,就像这样。

给定一个整数的链表,删除每个第m个节点并返回

最后剩余的节点。


例如:链表= 4-> 6-> 7-> 3-> 5-> 6-> 10-> 1-> ; 23-> 17

删除每第3个节点(m = 3)并返回最后剩余的节点

意思是......

4 - > 6-> 3-> 5-> 10-> 1-> 17

4-> 3-> 5-> 1-> 17

3-> 5-> 17

3-> 17

3


删除每个第3个节点后,剩下的最后一个节点是3,所以返回数据为3的节点



函数原型:


node * deleteEveryMth(node ** head,int m)

{

// ....你的代码


}


谢谢

A

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

推荐答案

Aditya说:
Aditya said:

这是一个正常的面试问题,就像这样

给定一个整数的链表,删除每个第m个节点并返回

最后剩余的节点。


例如:链表= 4-> 6-> 7-> 3-> 5-> 6-> 10-> 1-> 23-> 17 >
删除每个第3个节点(m = 3)并返回最后剩余的节点

意思是......

4-> 6-> 3- > 5-> 10-> 1-> 17

4-> 3-> 5-> 1-> 17

3- > 5-> 17

3-> 17

3


删除每个第3个节点后剩下的最后一个节点是3,所以节点

返回数据3.

函数原型:


节点* deleteEveryMth(节点**头) ,int m)

{

// ....你的代码
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



不,你的。< br $>

-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名, - www。

No, yours.

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


Aditya写道:
Aditya wrote:

这是一个正常的面试问题,就像这样

给定一个整数链表,删除每个第m个节点并返回

最后剩下的节点。
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."



请不要发布到多个团体,如果你必须交叉,或者更好

仍然,发布到一个小组。


-

Ian Collins。

Please don''t post to multiple groups, cross post if you must, or better
still, post to one group.

--
Ian Collins.


2006年12月20日01 :36:00-0800,Aditya < ad ***** @ gmail.comwrote:
On 20 Dec 2006 01:36:00 -0800, "Aditya" <ad*****@gmail.comwrote:

>这是一个正常的面试问题,就像这个
>This is a normal interview question, which goes like this



我从来没有在采访中问过这个问题,我也没想过。

我想我一定是不正常的。

I''ve never asked this question in an interview, nor do I ever plan to.
I guess I must be abnormal.


>"给定一个整数的链接列表,删除每个第m个节点并返回
最后剩余的节点。

例如:Linked list = 4 - > 6-> 7-> 3-> 5-> 6-> 10-> 1-> 23-> 17
删除每第3个节点(m = 3)和返回最后剩余的节点
意思是......
4-> 6-> 3-> 5-> 10-> 1-> 17> 4->删除后删除3-> 5-> -1-> 17
3-> 5-> 17
3-> 17

每个第3个节点最后剩下的节点为3,因此返回带有数据3的节点。
函数原型:

node * deleteEveryMth(node ** head,int m)
{

// ....你的代码

}
>"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

}



我没有任何线索。


但是,如果,何时,我需要知道如何删除

a链接整数列表中的每个第m个节点,我会花时间学习如何做到这一点

对,我会做对的。而且客户会为我付出很高的代价




在接受采访时,我开始提出非常简单的问题,比如

以下陈述有什么问题?


void main(void);

i = i ++%MAX_VAL;

p =(int *)malloc(4 * 4);

int main(void){return -1;}

goto ERROR;

得到;

fflush(STDIN);

#define N X + 1

unsigned i; for(i = 1; i> = 0; i--)

while(1)


一旦他们回答了这些问题,通常会很容易确定面试的地点




-

jay

I have no clue.

But if, and when, I ever need to know how to delete every mth node in
a linked list of integers, I''ll spend the time to learn how to do it
right, and I''ll get it right. And the customer will pay me dearly for
it.

At an interview, I start off with asking very simple questions, like
what''s wrong with the following statements?

void main(void);
i = i++ % MAX_VAL;
p = (int*)malloc(4 * 4);
int main(void) {return -1;}
goto ERROR;
gets(s);
fflush(STDIN);
#define N X+1
unsigned i; for(i=1;i>=0;i--)
while(1)

Once they answer those questions, it''s usually easy to determine where
the interview is headed.

--
jay


这篇关于删除链表中的每个第m个元素??的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆