链表:如何利用“假头,新指针,双指针”解决链表问题

Java学习+面试指南:https://javaxiaobear.cn

链表是一种线性数据结构,其中的每个元素实际上是一个单独的对象,而所有对象都通过每个元素中的引用字段链接在一起。

链表是一种物理存储单元上非连续、非顺序的存储结构,其物理结构不能只管的表示数据元素的逻辑顺序,数据元素的逻辑顺序是通过链表中的指针链接次序实现的。链表由一系列的结点(链表中的每一个元素称为结点)组成,结点可以在运行时动态生成。

public class LinkedList<T>{/*** 存储元素*/private T item;/*** 指向下一节点*/private LinkedList next;public LinkedList(T item, LinkedList next) {this.item = item;this.next = next;}
}

1、单链表

单链表中的每个结点不仅包含值,还包含链接到下一个结点的引用字段。通过这种方式,单链表将所有结点按顺序组织起来。

单向链表是链表的一种,它由多个结点组成,每个结点都由一个数据域和一个指针域组成,数据域用来存储数据,指针域用来指向其后继结点。链表的头结点的数据域不存储数据,指针域指向第一个真正存储数据的结点。

1、添加元素

如果我们想在给定的结点 prev 之后添加新值,我们应该:

  1. 使用给定值初始化新结点 cur;

  2. 将 cur 的 next 字段链接到 prev 的下一个结点 next ;

  3. 将 prev 中的 next 字段链接到 cur 。

与数组不同,我们不需要将所有元素移动到插入元素之后。因此,我们可以在 O(1) 时间复杂度中将新结点插入到链表中,这非常高效。

在开头添加节点

我们使用头结点开始遍历整个链表,头结点对我们来说是非常重要的。

步骤:

  1. 初始化一个新节点cur
  2. 将新节点链接到我们的原始节点head
  3. 将cur指定为head
2、删除元素

让我们尝试把结点 6从上面的单链表中删除。

  1. 从头遍历链表,直到我们找到前一个结点 prev,即结点 23

  2. 将 prev(结点 23)与 next(结点 15)链接

结点 6 现在不在我们的单链表中。

3、代码实现
public class SinglyListNode<T> implements Iterable<T> {/*** 记录头结点*/private LinkedList head;/*** 链表长度*/private int n;public SinglyListNode() {head = new LinkedList(null,null);n = 0;}/*** 清空链表* 头结点.next 指向下一节点为空,头结点元素为空,链表长度为空*/public void clear(){head.next = null;head.item = null;n = 0;}/*** 链表长度* @return n*/public int length(){return n;}/*** 判断链表是否为空* @return*/public boolean isEmpty(){return n==0;}/*** 链表增加元素,最后节点* @param t 元素*/public void insertNode(T t){//获取头结点LinkedList linkedList = head;//寻找最后一个节点while(null != linkedList.next){linkedList = linkedList.next;}//初始化插入的节点,下一节点为空LinkedList linkedList1 = new LinkedList(t, null);//最后节点的next指向下一节点linkedList.next = linkedList1;//链表长度+1n++;}/*** 指定位置插入元素* @param i 插入位置* @param t 元素*/public void insertNode(int i,T t){//获取头结点LinkedList pre = head;//获取插入元素的前一节点for (int j = 0; j < i; j++) {pre = pre.next;}//获取下一节点(位于i的节点)LinkedList next = pre.next;//初始化插入节点,且next指向插入元素的下一节点(位于i的节点)LinkedList tLinkedList = new LinkedList(t, next);//插入元素的前一节点指向插入元素pre.next = tLinkedList;//链表长度+1n++;}/*** 删除指定位置的节点* @param i*/public T delete(int i){//获取头结点LinkedList pre = head;for (int j = 0; j < i; j++) {pre = pre.next;}//当前i位置的结点LinkedList next = pre.next;//前一个结点指向下一个结点,删除当前结点pre.next = next.next;//长度-1n--;return next.item;}public T getIndexOf(int i){LinkedList pre = head;for (int j = 0; j < i; j++) {pre = pre.next;}LinkedList next = pre.next;return next.item;}private class LinkedList{/*** 存储元素*/T item;/*** 指向下一节点*/LinkedList next;public LinkedList(T item,LinkedList next) {this.item = item;this.next = next;}}@Overridepublic Iterator<T> iterator() {return new LIterator();}private class LIterator implements Iterator<T>{private LinkedList n;public LIterator() {this.n = head;}@Overridepublic boolean hasNext() {return n.next!=null;}@Overridepublic T next() {n = n.next;return (T) n.item;}}
}

测试类

public class SinglyListNodeTest{public static void main(String[] args) {SinglyListNode<String> head = new SinglyListNode<>();head.insertNode(0,"张胜男");head.insertNode(1,"李四");head.insertNode(2,"王五");head.insertNode(3,"6666");head.insertNode(4,"7777");for (String s : head) {System.out.println(s);}head.delete(0);String indexOf = head.getIndexOf(3);System.out.println(indexOf);for (String s : head) {System.out.println(s);}}
}

2、双链表

双向链表也叫双向表,是链表的一种,它由多个结点组成,每个结点都由一个数据域和两个指针域组成,数据域用
来存储数据,其中一个指针域用来指向其后继结点,另一个指针域用来指向前驱结点。链表的头结点的数据域不存
储数据,指向前驱结点的指针域值为null,指向后继结点的指针域指向第一个真正存储数据的结点。

我们可以与单链表相同的方式访问数据:

  1. 我们不能在常量级的时间内访问随机位置。
  2. 我们必须从头部遍历才能得到我们想要的第一个结点。
  3. 在最坏的情况下,时间复杂度将是 O(N),其中 N 是链表的长度
1、添加元素

如果我们想在现有的结点 prev 之后插入一个新的结点 cur,我们可以将此过程分为两个步骤:

  1. 链接 cur 与 prev 和 next,其中 next 是 prev 原始的下一个节点;

  2. 用 cur 重新链接 prev 和 next。

2、删除链表

如果我们想从双链表中删除一个现有的结点 cur,我们可以简单地将它的前一个结点 prev 与下一个结点 next 链接起来。

与单链表不同,使用“prev”字段可以很容易地在常量时间内获得前一个结点。

因为我们不再需要遍历链表来获取前一个结点,所以时间和空间复杂度都是O(1)。

我们的目标是从双链表中删除结点 6。

因此,我们将它的前一个结点 23 和下一个结点 15 链接起来:

3、代码实现
package com.xiaobear.LinkedList;import java.util.Iterator;/*** @Author xiaobear* @date 2021年07月27日 14:11* @Description 双向链表*/
public class DoublyLinkedList<T> implements Iterable<T>{/*** 链表长度*/private int n;/*** 头结点*/private Node head;/*** 尾结点*/private Node last;/*** 初始化链表*/public DoublyLinkedList() {head = new Node(null,null,null);last = null;n = 0;}/*** 清空链表*/public void clear(){head = null;last = null;n = 0;}/*** 链表是否为空* @return*/public boolean isEmpty(){return n==0;}/*** 数组长度* @return*/public int length(){return n;}/*** 插入元素t* @param t*/public void insert(T t){if (last==null){last = new Node(t,head,null);head.next = last;}else{Node oldLast = last;Node node = new Node(t, oldLast, null);oldLast.next = node;last = node;}//长度+1n++;}/*** 指定位置插入元素* @param i* @param t*/public void insert(int i,T t){if (i < 0 || i >= n){throw new RuntimeException("位置不合法");}Node pre = head;for (int j = 0; j < i; j++) {pre = pre.next;}//插入位置的下一节点Node nextNode = pre.next;//初始化节点Node newNode = new Node(t, pre, nextNode);//插入节点的前一节点指向headnextNode.pre = newNode;pre.next = newNode;n++;}/*** 尾部插入元素* @param t*/public void insertLast(T t){insert(n,t);}/*** 获取第一个元素* @return*/public T getFirst(){if(isEmpty()){return null;}return head.next.item;}/*** 获取最后一个元素* @return*/public T getLast(){if(isEmpty()){return null;}return last.item;}/*** 获取第i个元素的值* @param i* @return*/public T getItem(int i){if (isEmpty()){return null;}Node firstNode = head.next;for (int j = 0; j < i; j++) {firstNode = firstNode.next;}return firstNode.item;}/*** 删除第I个元素* @param i* @return*/public T remove(int i){Node pre = head;for (int j = 0; j < i; j++) {pre = pre.next;}//获取当前元素Node cur = pre.next;Node curNext = cur.next;pre.next = curNext;curNext.pre = pre;n--;return cur.item;}@Overridepublic Iterator<T> iterator() {return new DIterator();}private class DIterator implements Iterator{private Node n = head;@Overridepublic boolean hasNext() {return n.next != null;}@Overridepublic Object next() {n = n.next;return n.item;}}/*** 节点类*/private class Node{//存储元素public T item;//前一节点public Node pre;//后一个节点public Node next;public Node(T item, Node pre, Node next) {this.item = item;this.pre = pre;this.next = next;}}
}
public class ListNode {int val;ListNode next;ListNode prev;ListNode(int x) { val = x; }
}class MyLinkedList {int size;// sentinel nodes as pseudo-head and pseudo-tailListNode head, tail;public MyLinkedList() {size = 0;head = new ListNode(0);tail = new ListNode(0);head.next = tail;tail.prev = head;}/** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */public int get(int index) {// if index is invalidif (index < 0 || index >= size) return -1;// choose the fastest way: to move from the head// or to move from the tailListNode curr = head;if (index + 1 < size - index)for(int i = 0; i < index + 1; ++i) curr = curr.next;else {curr = tail;for(int i = 0; i < size - index; ++i) curr = curr.prev;}return curr.val;}/** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */public void addAtHead(int val) {ListNode pred = head, succ = head.next;++size;ListNode toAdd = new ListNode(val);toAdd.prev = pred;toAdd.next = succ;pred.next = toAdd;succ.prev = toAdd;}/** Append a node of value val to the last element of the linked list. */public void addAtTail(int val) {ListNode succ = tail, pred = tail.prev;++size;ListNode toAdd = new ListNode(val);toAdd.prev = pred;toAdd.next = succ;pred.next = toAdd;succ.prev = toAdd;}/** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */public void addAtIndex(int index, int val) {// If index is greater than the length, // the node will not be inserted.if (index > size) return;// [so weird] If index is negative, // the node will be inserted at the head of the list.if (index < 0) index = 0;// find predecessor and successor of the node to be addedListNode pred, succ;if (index < size - index) {pred = head;for(int i = 0; i < index; ++i) pred = pred.next;succ = pred.next;}else {succ = tail;for (int i = 0; i < size - index; ++i) succ = succ.prev;pred = succ.prev;}// insertion itself++size;ListNode toAdd = new ListNode(val);toAdd.prev = pred;toAdd.next = succ;pred.next = toAdd;succ.prev = toAdd;}/** Delete the index-th node in the linked list, if the index is valid. */public void deleteAtIndex(int index) {// if the index is invalid, do nothingif (index < 0 || index >= size) return;// find predecessor and successor of the node to be deletedListNode pred, succ;if (index < size - index) {pred = head;for(int i = 0; i < index; ++i) pred = pred.next;succ = pred.next.next;}else {succ = tail;for (int i = 0; i < size - index - 1; ++i) succ = succ.prev;pred = succ.prev.prev;}// delete pred.next --size;pred.next = succ;succ.prev = pred;}
}

3、链表反转

定义一个函数, 输入一个链表的头节点, 反转该链表并输出反转后链表的头节点。

原链表中数据为:1->2->3>4

反转后链表中数据为:4->3->2->1

1、递归

回顾递归的模板

public ListNode reverseList(ListNode head){if(终止条件){return;}//逻辑处理//递归调用ListNode temp = reverseList(参数);//逻辑处理
}

终止条件:链表为空或者链表没有尾节点的时候

if(head == null || head.next == null){return head;
}

怎样递归调用:从当前节点的下一节点开始递归

逻辑处理:把当前节点挂在递归之后的链表的末尾

    /*** 链表反转*/public void reverse(){if(null == head){return;}//从下一节点开始reverseList(head.next);}/*** 链表反转* @param curr* @return*/public LinkedList reverseList(LinkedList curr){//如果链表的下一节点为空if(null == curr.next){head.next = curr;return curr;}//当前节点的上一个节点LinkedList pre = reverseList(curr.next);pre.next = curr;//当前节点的下一节点指向nullcurr.next = null;//返回当前节点return curr;}

第二种:

public ListNode reverseList(ListNode head){if(null == head || null ==head.next){return head;}//保存当前节点的下一节点ListNode temp = head.next;//开始递归调用,reverse就是反转之后的链表,不包括头结点ListNode reverse = reverseList(temp);//将头结点挂在当前节点的后面temp.next = head;//反转之后头节点变成尾节点了,下一节点为空head.next = null;return reverse;
}

因为递归调用之后h e a d . n e x t 节点就会成为r e v e r s e 节点的尾结点, 我们可以直接让h e a d . n e x t . n e x t = h e a d ; , 这样代码会更简洁一些。

public ListNode reverse(ListNode head){if(null == head || null ==head.next){return head;}ListNode reverse = reverse(head.next);head.next.next = head;head.next = null;return reverse;
}

这种递归往下传递的时候基本上没有逻辑处理, 当往回反弹的时候才开始处理, 也就是从链表的尾端往前开始处理的。我们还可以再来改一下, 在链表递归的时候从前往后处理, 处理完之后直接返回递归的结果, 这就是所谓的尾递归, 这种运行效率要比上一种好很多。

public ListNode reverseList(ListNode head){return reverseListEnd(head, null);
}
public ListNode reverseListEnd(ListNode head, ListNode newNode){if(head == null){return newNode;}//当前节点的下一节点ListNode next = head.next;head.next = newNode;ListNode node = reverseListEnd(next,head);return node;
}
2、双链表

双链表求解是把原链表的结点一个个摘掉, 每次摘掉的链表都让它成为新的链表的头结点, 然后更新新链表。

public ListNode reverseList(ListNode head){//初始化新链表ListNode result = null;while(head != null){//保存当前节点的下一节点ListNode temp = head.next;//每次访问的原链表节点都会成为新链表的头结点head.next = result;//更新新链表result = head;//重新赋值head = temp;}return result;
}
3、栈

栈的原理:先进后出

实现原理就是把链表节点一个个入栈, 当全部入栈完之后再一个个出栈, 出栈的时候在把出栈的结点串成一个新的链表。

public LinkedList reverseListByStack(ListNode head){Stack<LinkedList> stack = new Stack<>();while (head != null){//链表入栈stack.push(head);head = head.next; }if(stack.isEmpty()){return null;}//栈中元素出栈LinkedList pop = stack.pop();LinkedList result = pop;while (!stack.isEmpty()){LinkedList pop1 = stack.pop();pop.next = pop1;pop = pop.next;}//最后一个结点就是反转前的头结点,一定要让他的next等于空,否则会构成环pop.next =null;return result;
}

4、快慢指针

快慢指针指的是定义两个指针,这两个指针的移动速度一块一慢,以此来制造出自己想要的差值,这个差值可以然我们找到链表上相应的结点。一般情况下,快指针的移动步长为慢指针的两倍

1、中间值问题

找到链表的中间元素并返回

利用快慢指针,我们把一个链表看成一个跑道,假设a的速度是b的两倍,那么当a跑完全程后,b刚好跑一半,以此来达到找到中间节点的目的。

public class FastAndSlowPointer {public static void main(String[] args) {Node<String> aa = new Node<>("aa", null);Node<String> bb = new Node<>("bb", null);Node<String> cc = new Node<>("cc", null);Node<String> dd = new Node<>("dd", null);Node<String> ee = new Node<>("ee", null);Node<String> ff = new Node<>("ff", null);Node<String> gg = new Node<>("gg", null);aa.next = bb;bb.next = cc;cc.next = dd;dd.next = ee;ee.next = ff;ff.next = gg;System.out.println("链表的中间元素为:"+getMiddle(aa));}/*** 寻找链表的中间元素* @param first 链表的头结点* @return 链表中间节点的值*/public static String getMiddle(Node<String> first){//定义两个指针分别等于firstNode<String> fast = first;Node<String> slow = first;while(null != fast && null != fast.next){fast = fast.next.next;slow = slow.next;}return slow.item;}public static class Node<T>{T item;Node next;public Node(T item, Node next) {this.item = item;this.next = next;}}
}

方法代码:

/*** 寻找链表的中间元素* @param first 链表的头结点* @return 链表中间节点的值*/
public String getMiddle(Node<String> first){//定义两个指针分别等于firstNode<String> fast = first;Node<String> slow = first;while(null != fast && null != fast.next){fast = fast.next.next;slow = slow.next;}return slow.item;
}
2、单向链表是否有环
  • 使用快慢指针的思想,还是把链表比作一条跑道,链表中有环,那么这条跑道就是一条圆环跑道,在一条圆环跑道中,两个人有速度差,那么迟早两个人会相遇,只要相遇那么就说明有环。
  • 使用哈希表,将链表的值存入Set中,如果有存在相同元素的,就说明有环
  • 快慢指针
/*** 判断链表是否有环--快慢指针* @param first 链表的头结点* @return*/
public static boolean isCircle(Node<String> first){//定义两个指针分别等于firstNode<String> fast = first;Node<String> slow = first;while(null != first && null != first.next){fast = fast.next.next;slow = slow.next;if(fast.equals(slow)){return true;}}return false;
}
  • 哈希表
/**** @param first* @return*/
public static boolean isCircleBySet(Node<String> first){Set<String> strings = new HashSet<>();while(null !=first){//将值存入set集合中if(!strings.add(first.item)){return true;}first = first.next;}return false;
}
3、有环链表入口问题

当快慢指针相遇时,我们可以判断到链表中有环,这时重新设定一个新指针指向链表的起点,且步长与慢指针一样为1,则慢指针与“新”指针相遇的地方就是环的入口

/*** 寻找有环链表的入口* @param first* @return*/
public String getEntrance(Node<String> first){//定义两个指针分别等于firstNode<String> fast = first;Node<String> slow = first;//新节点Node<String> temp = null;while(null != first && null != first.next){fast = fast.next.next;slow = slow.next;//快慢指针相遇,初始化新节点,接着遍历if(fast.equals(slow)){temp = first;continue;}if(null != temp){temp = temp.next;if(temp.equals(slow)){return temp.item;}}}return null;
}

5、循环链表

循环链表,顾名思义,链表整体要形成一个圆环状。在单向链表中,最后一个节点的指针为null,不指向任何结点,因为没有下一个元素了。要实现循环链表,我们只需要让单向链表的最后一个节点的指针指向头结点即可。

6、约瑟夫问题

传说有这样一个故事,在罗马人占领乔塔帕特后,39 个犹太人与约瑟夫及他的朋友躲到一个洞中,39个犹太人决定宁愿死也不要被敌人抓到,于是决定了一个自杀方式,41个人排成一个圆圈,第一个人从1开始报数,依次往后,如果有人报数到3,那么这个人就必须自杀,然后再由他的下一个人重新从1开始报数,直到所有人都自杀身亡为止。然而约瑟夫和他的朋友并不想遵从。于是,约瑟夫要他的朋友先假装遵从,他将朋友与自己安排在第16个与第31个位置,从而逃过了这场死亡游戏 。

问题转换:

41个人坐一圈,第一个人编号为1,第二个人编号为2,第n个人编号为n。
1.编号为1的人开始从1报数,依次向后,报数为3的那个人退出圈;
2.自退出那个人开始的下一个人再次从1开始报数,以此类推;
3.求出最后退出的那个人的编号。

解题思路:

  1. 构建含有41个结点的单向循环链表,分别存储1~41的值,分别代表这41个人;
  2. 使用计数器count,记录当前报数的值;
  3. 遍历链表,每循环一次,count++;
  4. 判断count的值,如果是3,则从链表中删除这个结点并打印结点的值,把count重置为0;
public class JosephQuestion {public static void main(String[] args) {//先构建循环链表Node<Integer> first = null;//记录当前节点的值Node<Integer> pre = null;for (int i = 1; i <= 41; i++) {//如果是第一个节点if(1 == i){first = new Node<>(i,null);pre = first;continue;}Node node = new Node(i, null);pre.next = node;//重置prepre = node;//构建循环链表,让最后一个结点指向第一个结点if (41 == i){pre.next = first;}}//记录当前的报数值int count = 0;Node<Integer> head = first;//记录当前节点Node<Integer> temp = null;while (head != head.next){count++;if(3 == count){//判断count的值,如果是3,则从链表中删除这个结点并打印结点的值,把count重置为0;temp.next = head.next;System.out.print(head.item+",");count = 0;}else {temp = head;}head = head.next;}System.out.println(head.item);}public static class Node<T>{T item;Node next;public Node(T item, Node next) {this.item = item;this.next = next;}}
}

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://xiahunao.cn/news/2660144.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

深入浅出图解C#堆与栈 C# Heap(ing) VS Stack(ing) 第六节 理解垃圾回收GC,提搞程序性能

深入浅出图解C#堆与栈 C# Heaping VS Stacking 第六节 理解垃圾回收GC&#xff0c;提搞程序性能 [深入浅出图解C#堆与栈 C# Heap(ing) VS Stack(ing) 第一节 理解堆与栈](https://mp.csdn.net/mdeditor/101021023)[深入浅出图解C#堆与栈 C# Heap(ing) VS Stack(ing) 第二节 栈基…

【kubernetes】集群网络(一):基础篇

Flannel 1 路由表 & arp & fdb 1.1 路由表 任何网络设备都需要路由表&#xff0c;路由表用来决定&#xff0c;当收到数据包时&#xff0c;该向哪里进行转发。路由表项通常会包含以下几个字段&#xff1a; Destination&#xff1a;目的地Gateway&#xff1a;网关Mas…

12.27重构二叉树,插入排序,队列(股票,模拟),后缀表达式求值,括号匹配,验证栈序列,选择题部分

重构二叉树 误 string in, post; struct node {char a;node* lchild, * rchild;node(char x\0) :a(x), lchild(nullptr), rchild(nullptr) {} }; void so(node* r, int il, int ir, int pl, int pr) {if (il > ir)return;int root;for (root il; root < ir; root) {if…

[AI编程]AI辅助编程助手-亚马逊AI 编程助手 Amazon CodeWhisperer

亚马逊AI 编程助手 Amazon CodeWhisperer 是一种基于人工智能技术的编程辅助工具&#xff0c;旨在帮助开发人员更高效地编写代码。它可以提供实时的代码建议、自动补全和错误检查&#xff0c;帮助优化代码质量和提高编程效率。 Amazon CodeWhisperer 使用了自然语言处理和机器…

OpenChat-3.5:70亿参数下的AI突破

引言 在对话AI的发展史上&#xff0c;OpenChat-3.5标志着一个新纪元的到来。拥有70亿参数的这一模型&#xff0c;不仅是对现有语言学习模型&#xff08;LLMs&#xff09;的重大改进&#xff0c;更是在多模态任务中树立了新的标准。 模型概述 OpenChat-3.5作为一款先进的多模…

Leetcode—1572.矩阵对角线元素的和【简单】

2023每日刷题&#xff08;七十三&#xff09; Leetcode—1572.矩阵对角线元素的和 实现代码 class Solution { public:int diagonalSum(vector<vector<int>>& mat) {int n mat.size();if(n 1) {return mat[0][0];}int sum 0;int i 0, j n - 1;while(i &…

ARM CCA机密计算软件架构之RMI领域管理接口与RSI领域服务接口

领域管理接口 领域管理接口&#xff08;RMI&#xff09;是RMM与正常世界主机之间的接口。 RMI允许正常世界虚拟机监视器向RMM发出指令&#xff0c;以管理领域。 RMI使用来自主机虚拟机监视器的SMC调用&#xff0c;请求RMM的管理控制。 RMI使得对领域管理的控制成为可能&…

自动化测试框架知识总结(超详细整理)

一、什么是自动化测试框架 在了解什么是自动化测试框架之前&#xff0c;先了解一下什么叫框架&#xff1f;框架是整个或部分系统的可重用设计&#xff0c;表现为一组抽象构件及构件实例间交互的方法;另一种定义认为&#xff0c;框架是可被应用开发者定制的应用骨架。前者是从应…

Java多线程常见的成员方法(线程优先级,守护线程,礼让/插入线程)

目录 1.多线程常见的成员方法2.优先级相关的方法3.守护线程&#xff08;备胎线程&#xff09;4.其他线程 1.多线程常见的成员方法 ①如果没有给线程设置名字&#xff0c;线程是有默认名字 的&#xff1a;Thread-X(X序号&#xff0c;从0开始) ②如果要给线程设置名字&#xff0c…

10 分钟了解 nextTick ,并实现简易版的 nextTick

前言 在 Vue.js 中&#xff0c;有一个特殊的方法 nextTick&#xff0c;它在 DOM 更新后执行一段代码&#xff0c;起到等待 DOM 绘制完成的作用。本文会详细介绍 nextTick 的原理和使用方法&#xff0c;并实现一个简易版的 nextTick&#xff0c;加深对它的理解。 一. 什么是 n…

sql优化,内外连接有什么区别

内外连接是啥不必多说&#xff0c;但在做关联查询的时候&#xff0c;二者是有一些区别的&#xff1a; 举例来说&#xff0c;首先是外连接&#xff08;左外连接为例&#xff09;&#xff0c;当两个表都没有索引&#xff0c;就都是全表扫描 EXPLAIN SELECT SQL_NO_CACHE * FROM …

19个Python语法糖和9个内置装饰器

19 个Sweet的 Python Syntax Sugar&#xff0c;用于改善您的编码体验 文章目录 19 个Sweet的 Python Syntax Sugar&#xff0c;用于改善您的编码体验1. 联合运算符Union Operators&#xff1a;合并 Python 字典的最优雅方式2. 类型提示Type Hints&#xff1a;使您的 Python 程序…

EduChat账号密码登录

内测申请&#xff1a;请邮件dan_yhstu.ecnu.edu.cn&#xff0c;以“EduChat内测申请单位”作为邮件标题&#xff0c;邮件内容中写明用途 先去申请个账号和密码&#xff0c;会有一两天延迟吧&#xff0c;挺快的。 拿到账号之后去官网,点一个 官网传送门 就出来用账号密码登录的…

腾讯云轻量服务器和云服务器CVM该怎么选?区别一览

腾讯云轻量服务器和云服务器CVM该怎么选&#xff1f;不差钱选云服务器CVM&#xff0c;追求性价比选择轻量应用服务器&#xff0c;轻量真优惠呀&#xff0c;活动 https://curl.qcloud.com/oRMoSucP 轻量应用服务器2核2G3M价格62元一年、2核2G4M价格118元一年&#xff0c;540元三…

六、Redis 分布式系统

六、Redis 分布式系统 六、Redis 分布式系统6.1 数据分区算法6.1.1 顺序分区6.1.2 哈希分区 6.2 系统搭建与运行6.2.1 系统搭建6.2.2 系统启动与关闭 6.3 集群操作6.3.1 连接集群6.3.2 写入数据6.3.3 集群查询6.3.4 故障转移6.3.5 集群扩容6.3.6 集群收缩 6.4 分布式系统的限制…

幼儿园:人脸识别门禁技术,可以提高工作效率?

随着社会的不断发展和科技的飞速进步&#xff0c;人脸识别技术已经成为各行各业的一项重要工具。 在幼儿园管理中&#xff0c;人脸识别技术的应用不仅提高了安全性&#xff0c;也优化了接送流程&#xff0c;为幼儿园、家长和孩子们带来了更便捷的管理和服务体验。 客户案例一 …

快解析结合用友T+异地访问解决方案

用友T作为一款纯BS架构软件&#xff0c;外网用户只需打开浏览器&#xff0c;输入域名即可访问T服务器。但是由于网络原因&#xff0c;很多客户没有公网IP&#xff0c;使T远程访问无法实现。快解析云解析版结合T使用&#xff0c;无需公网IP、无需在路由器里开放端口&#xff0c;…

C++系列-第3章循环结构-26-认识do-while语句

C系列-第3章循环结构-26-认识do-while语句 在线练习&#xff1a; http://noi.openjudge.cn/ https://www.luogu.com.cn/ 对于 while 语句而言&#xff0c;如果不满足条件&#xff0c;则不能进入循环。但有时候我们需要即使不满足条件&#xff0c;也至少执行一次。 do-while循环…

Vue(一):Vue 入门与 Vue 指令

Vue 01. Vue 快速上手 1.1 Vue 的基本概念 用于 构建用户界面 的 渐进性 框架 构建用户界面&#xff1a;基于数据去渲染用户看到的界面渐进式&#xff1a;不需要学习全部的语法就能完成一些功能&#xff0c;学习是循序渐进的框架&#xff1a;一套完整的项目解决方案&#x…

Redis管道

问题引出 Redis是一种基于客户端-服务端模型以及请求/响应协议的TCP服务。一个请求会遵循以下步骤&#xff1a; 1 客户端向服务端发送命令分四步(发送命令→命令排队→命令执行→返回结果)&#xff0c;并监听Socket返回&#xff0c;通常以阻塞模式等待服务端响应。 2 服务端…