1. 合并两个排序链表(老问题,用C实现吧)
2.100个整数组成的数组,打乱次序,拿掉其中一个数,把它找出来( 运用另外一个数学技巧可以几行代码搞定 )
//1.
const node *merge_lists(const node *head1, const node *head2)
{
const node *head;
const node *cur;
if (NULL == head1)
{
return head2;
}
if (NULL == head2)
{
return head1;
}
if (head1->data < head2->data)
{
head = head1;
head1 = head1->next;
}
else
{
head = head2;
head2 = head2->next;
}
for (cur = head; head1 != NULL && head2 != NULL; )
{
if (head1->data < head2->data)
{
cur->next = head1;
cur = head1;
head1 = head1->next;
}
else
{
cur->next = head2;
cur = head2;
head2 = head2->next;
}
}
cur->next = (NULL == head1) ? head2 : head1;
return head;
}
//2.src1为没有缺失数的数组,src2为缺少了一个数的数组,size为没有缺失的数组的总数目
int get_lost_number(const src1[], const src2[], int size)
{
int lost;
int i;
assert (src1 != NULL && src2 != NULL && size > 0);
for (lost = 0, i = 0; i < size - 1; ++i)
{
lost ^= src1[i];
lost ^= src2[i];
}
return lost ^ src1[i];
}