操作系统
- 进程与线程的区别 答:进程作为资源分配的基本单位、线程作为任务调度的基本单位,线程的粒度比进程更小、一个进程至少包含一个线程。同一个进程内多线程资源共享。
- 进程之间如何切换
答:1.保存当前进程执行上下文到PCB, 将PCB状态置为等待或就绪,并加入等待或就绪队列。
- 调度服务程序选择一个将要执行的程序,将PCB状态设置为运行,再将执行上下文从PCB释放到CPU寄存器中。
算法与数据结构
- 如何判断两个单链表是否相交,返回相交的第一个节点,否则返回null
function isMixin(head1,head2){
}
不方便写代码,给思路也可
答:第一步:将两个单链表都遍历到最后一个元素,比较是否相等,如果相等表示相交,否则直接返回null
第二步:如果确定两个链表相交,则将最后一个元素的next指针指向任意一个链表的head,形成一个循环链表,那么问题就从找第一个相交节点,变成找循环链表的循环起点了
第三步:利用快慢指针,fast一次走两步,slow一次走一步,当两者相遇时,将其中任意指针重新置回head, 再同步前进(都每次走一步),两次相遇时的那个结点,就是相交的第一个结点(数学关系不好推0.0)
css
<div id="parent">
<div id="child">child</div>
</div>
子元素水平居中的方式有哪些
子元素垂直居中的方式有哪些
答:
第一种
#parent{
width: 500px;
height: 500px;
background-color: pink;
display: flex;
justify-content: center; /*水平居中*/
align-items: center; /*垂直居中*/
}
#child {
width: 300px;
height: 300px;
background-color: red;
}
第二种:
#parent{
width: 500px;
height: 500px;
background-color: pink;
}
#child {
width: 300px;
height: 300px;
background-color: red;
margin: 0 auto; /*水平居中*/
}
第三种:
#parent{
position: relative;
width: 500px;
height: 500px;
background-color: pink;
}
#child {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%); /*水平垂直居中*/
width: 300px;
height: 300px;
background-color: red;
}