一面:
2020.07.29
链表相交,
实现memcpy函数,
new和malloc的区别
memcpy函数的实现:
void *memcpy(void *pDest, const void*pSrc, unsigned int n) {
assert((NULL != pDest)&&(NULL != pSrc))
char *pTmpDest = (char*)pDest;
char *pTmpSrc = (char*)pSrc;
while(n--) {
*pTmpDest = *pTmpSrc;
pTmpDest++;
pTmpSrc++;
}
return pDest;
}
void* upgrade_memcpy(void* pDest, const void* pSrc, size_t n) {
assert((pDest!=NULL)&&(pSrc!=NULL))
int wordnum = n/4;
int slice = n%4;
int * pIntsrc = (int*)pSrc;
int * pIntdest = (int*)pDest;
while(wordnum--)
*pIntdest++ = *Intsrc++;
while(slice--)
*((char*)pIntdest)++ = *((char*)pIntsrc)++;
return pDest;
}
二面
2020.08.05
1、多线程
2、IPC、共享内存
3、bind
4、合并n个有序链表 (力扣原题 使用最小堆会快一些)
#include <queue>
using namespace std;
struct ListNode {
int val;
ListNode* next;
ListNode(int x) : val(x), next(NULL) {}
};
class Solution {
struct cmp {
bool operator() (ListNode* a, ListNode* b) {
return a->val > b->val;
}
};
ListNode* mergeKLists(vector<ListNode*>& lists) {
priority_queue<ListNode*, vector<ListNode*>, cmp> pri;
for (auto &elem : lists) {
if (elem) {
pri.push(elem);
}
}
ListNode* head = new ListNode(0);
ListNode* pre = head;
while(!pri.empty()) {
pre->next = pri.top();
ListNode* tmp = pri.top()->next;
pri.pop();
if (tmp) {
pri.push(tmp);
}
pre = pre->next;
}
pre = head->next;
delete head;
return pre;
};
};