问题 问答题


已知一个带有表头结点的单链表,结点结构为,假设该链表只给出了头指针list。在不改变链表的前提下,请设计一个尽可能高效的算法,查找链表中倒数第k个位置上的结点(k为正整数)。若查找成功,算法输出该结点的data值,并返回1;否则,只返回0。要求:

描述算法的基本设计思想;

答案

参考答案:

解析:算法基本思想如下:从头至尾遍历单链表,并用指针p指向当前结点的前k个结点。当遍历到链表的最后一个结点时,指针p所指向的结点即为所查找的结点。

选择题
填空题

How many of us would temp for three years while we waited for the perfect job Not many of us, perhaps. But Wentworth Miller, the "Prison Break" star, said he chose to wait even longer time (1) he found the right job.
"Actually I think it might have been three or four years until I was lucky enough to get guest (2) on TV shows," said Miller, 34, who rose to international stardom (3) to "Prison Break" in 2006. That kind of patience and p will was portrayed in "Prison Break". Miller (4) engineering wizard Michael Scofield, who tries everything to break out of a Chicago (5) with his brother. Miller said he was fond of his character, (6) he said "exists in shades of grey".
Miller comes from a (7) of teachers. He said he didn’t seem fated for a career in the arts, (8) his passion for acting. After (9) from Princeton with an English degree, he moved (10) his parents’ request to Los Angeles to look for a stable life. He started (11) in a little company that made television movies. This (12) simply faxing, filing, walking the boss’ dog and going to the store for the boss’ lunch. Every weekend during the summer, Miller (13) go to the office (14) he didn’t have air-conditioning. "I would hang (15) in the conference room and set up camp and rob the company kitchen," recalled Miller.
(16) , Miller realized he still had questions about his choice. He decided to quit. But the boss said he was making a mistake and offered him a well-paid assistant position. "I eventually (17) that if I did the corporate job, it would be great if I was successful, but I would always wonder about the (18) . If I did the acting and was successful, I would never wonder (19) that job," he explained. He quit and temped (20) many people in the entertainment industry.
Now, he’s a hot star and has people coming up to him at film festivals saying, "Weren’t you the one who (21) to stand by the copy machine "
"That was tough, but I’m glad I have that perspective. Because now I’m at a point (22) big shots laugh at all my jokes and I think, You know, I got coffee for people like you for six years’. So I know what’s (23) , because I’ve seen the other side." But what if, when he was offered the corporate job, there had been more money "It was never about the (24) There’s a kind of excitement that comes along with acting. I can’t find it anywhere else. Even if I had to go back to temping, even if this is not the beginning of an amazing career, I would not (25) making that jum
p.\