坛子里看的2个笔试题

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];
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值