G*O 发帖数: 706 | 1 【 以下文字转载自 Programming 讨论区 】
发信人: GTO (呵呵), 信区: Programming
标 题: 一道微软面试题
发信站: BBS 未名空间站 (Sun Aug 5 15:56:59 2007), 转信
Implement the following function for sorting a linked list of integers in
ascending order.
Your function should use only a constant amount of memory.
It's prohibited to change the value of ListNode, instead ListNodes must be
rearranged.
struct ListNode
{
int value() { return _value; }
ListNode *pNext;
private:
int _value;
};
ListNode* SortList(ListNode *pHead)
{
| G****n 发帖数: 618 | 2 Using insertion sort like algorithm will do.
【在 G*O 的大作中提到】 : 【 以下文字转载自 Programming 讨论区 】 : 发信人: GTO (呵呵), 信区: Programming : 标 题: 一道微软面试题 : 发信站: BBS 未名空间站 (Sun Aug 5 15:56:59 2007), 转信 : Implement the following function for sorting a linked list of integers in : ascending order. : Your function should use only a constant amount of memory. : It's prohibited to change the value of ListNode, instead ListNodes must be : rearranged. : struct ListNode
| R****r 发帖数: 227 | 3 2^32 buckets is certainly a constant amount of memory :P
【在 G*O 的大作中提到】 : 【 以下文字转载自 Programming 讨论区 】 : 发信人: GTO (呵呵), 信区: Programming : 标 题: 一道微软面试题 : 发信站: BBS 未名空间站 (Sun Aug 5 15:56:59 2007), 转信 : Implement the following function for sorting a linked list of integers in : ascending order. : Your function should use only a constant amount of memory. : It's prohibited to change the value of ListNode, instead ListNodes must be : rearranged. : struct ListNode
|
|