對LinkedList ,單鏈表和雙鏈表的理解

?一.ArrayList的缺陷
?二.鏈表
?三.鏈表部分相關oj面試題
? ? ?四.LinkedList的模擬實現
? ? ?五.LinkedList的使用
? ? ?六.ArrayList和LinkedList的區別
一.ArrayList的缺陷:
1. ArrayList底層使用 數組 來存儲元素,如果不熟悉可以來再看看: ArrayList與順序表-CSDN博客
由于其底層是一段連續空間,當 ArrayList 任意位置插入或者刪除元素時,就需要將后序元素整體往前或者往后 搬移,時間復雜度為 O(n) ,效率比較低,因此 ArrayList 不適合做任意位置插入和刪除比較多的場景 。因此: java集合中又引入了 LinkedList,即鏈表結構
二.鏈表
1.鏈表的概念及結構:鏈表是一種 物理存儲結構上非連續 存儲結構,數據元素的 邏輯順序 是通過鏈表中的引用鏈接次序實現的就像一個火車。
注意:1鏈表在邏輯上是連續的,在物理結構上不一定連續。
2.節點一般都是從堆上申請出來的
? ? ? ? ??3.從堆上申請出來空間,是有它的分配規律和策略的,兩次申請出來的可能連續也可能不續
2.鏈表的分類
單向或者雙向循環和非循環帶頭和不帶頭就可以組合出8種類型的鏈表
雖然有這么多的鏈表的結構,但是我們重點掌握兩種:
(1) 無頭單向非循環鏈表:結構簡單, 一般不會單獨用來存數據。實際中更多是 作為其他數據結構的子結構,哈希桶、圖的鄰接表等等。另外這種結構在筆試面試中出現很多。
(2)無頭雙向鏈表:在Java的集合框架庫中LinkedList底層實現就是無頭雙向循環鏈表
?

3.無頭單向非循環鏈表實現
自己定義的類和包:


這里可以把方法先寫在一個接口中,再通過MyLinkList實現接口,這樣寫可能更好,代碼好復用。
我們
MyLinkList類中:我們要先抽象出每一個節點,每一個節點就是一個對象,我們可以寫一個產生節點對象的模板:(這里可以定義一個靜態 內部類,來抽象出節點模板):
public class MyLinkList {public int data;public MyLinkList.Node next;//靜態內部類public static class Node {public int data;//0public Node next;//引用類型默認值為NULLpublic Node(int data) {this.data = data;}}
}

(1)頭插方法:
public void addFirst(int data) {//第一次插入節點(鏈表為空)if (this.head == null) {Node node = new Node(data);//鏈表頭為空時(head == null),整了鏈表的頭引用為 nodethis.head = node;return;}//鏈表不為空,單鏈表插入要先綁后面Node node = new Node(data);node.next = this.head;head = node;//把node的引用給head,然head變成新的頭}

(2)尾插法:

public void addList(int data) {//第一次插入時if (this.head == null) {Node node = new Node(data);head = node;return;}Node node = new Node(data);Node cur = this.head;//cur從頭開始/*這里注意cur不可以先走到空,如果cur走到null,那么cur的next就是cull*/while (cur.next != null) {cur = cur.next;}//出來時cur==null,就尾插cur.next = node;}

(3)打印單鏈表:這里我們可以寫一個,重載方法display2,可以讓鏈表從返回的某個節點開始打印;

    //打印單鏈表public void display2(Node nodeH) {Node cur = this.head;//cur從頭開始cur = nodeH;while (cur != null) {System.out.print(cur.data + " ");cur = cur.next;}System.out.println();}public void display() {Node cur = this.head;//cur從頭開始while (cur != null) {System.out.print(cur.data + " ");cur = cur.next;}System.out.println();}

(4)查找鏈表中是否包含某一數據節點:

 //查找是否包含關鍵字Key,是否在鏈表中public boolean contains(int key) {Node cur = this.head;while (cur != null) {if (cur.data == key) {return true;}cur = cur.next;}return false;}

?
(5)清空鏈表:
public void clear() {Node cur = head;while (cur != null) {//注意定義一個,變量記住置為空的,后驅節點Node curN = cur.next;cur.next =null;//引用類型必須制空cur = curN;}//最后把頭節點手動置為nullhead = null;}

(6).返回鏈表的長度:

public int size() {Node cur = this.head;int count = 0;//count不能為1,如果是空鏈表,count=1返回就,寄了while (cur != null) {cur = cur.next;count++;}return count;}

(7)任意位置插入:這里我畫了個圖來理解:

//任意位置插入(第一個數據節點為0號下標)public void addIndex(int index, int data) {//相當于頭插if (index == 0) {addFirst(data);return;}//相當于尾插if (index == this.size()) {addList(data);return;}//正常插入方法:/***    1. 先找到index前一個節點的地址->定義一個cur走index-1步*    2.畫圖插入*///先找到index前一個節點的地址Node cur = searchIndex(index);//插入Node node = new Node(data);/*** 這里注意,先綁后面(node = cur.next;),因為單鏈表前一個節點負責,單獨的維護后一個節點,前一個節點的引用被覆蓋(cur節點)* 那么原本和cur節點連接的節點就找不到了*/node.next = cur.next;cur.next = node;}//找到index前一個節點的地址的方法private Node searchIndex(int index) {//index下標位置檢驗if (index < 0 || index > this.size()) {throw new RuntimeException("下標位置不合法");}Node cur = this.head;while (index-1 != 0/*走index-1步*/) {cur = cur.next;index--;}return cur;//返回走index-1步后的,cur類型地址}

(8)刪除指定位置節點:
 //找key節點的前驅private Node searchPrev(int key) {Node prev = this.head;while(prev.next != null) {if (prev.next.data == key) {return prev;}else {prev = prev.next;//繼續往后走}}return null;}//刪除第一次出現關鍵字為key的節點public void remove(int key) {/** 1. 找到,要刪除節點del的前驅*  2. 找到要刪除的節點del*  3. 刪除節點*///空節點直接返回if (this.head == null) {return;}//頭節點直接刪除if (this.head.data == key) {head = head.next;return;//這里注意別忘記了}//1. 找到,要刪除節點del的前驅Node prev = searchPrev(key);if (prev == null) {throw new RuntimeException("沒有你要刪除的節點,請考量要刪除的節點");}//2. 找到要刪除的節點delNode del = prev.next;//3. 刪除節點prev.next = del.next;}

(9)只遍歷一遍鏈表,刪除所有指定的節點:這里我畫了一個圖可以幫助理解:定義一個一直往后走快指針,和一個,不需要時往后走判斷是否要刪除慢指針

 //遍歷單鏈表一遍,刪除所有值為key的節點public void removeAllKey(int key) {/** 1.定義一個快指針 cur : cur指針一直往后走;*  2.定義一個慢指針 prev: prev指針,只有cur遇到要刪除的數據時,prev指針才往后走,不然保持不動*  3.注意最后不要漏了,head頭節點*/// 1.定義一個 cur指針 : cur指針一直往后走//  2.定義一個 prev指針: prev指針,只有cur遇到要刪除的數據時,prev指針才往后走,不然保持不動Node cur = this.head.next;//Node prev = this.head;while (cur != null) {if (cur.data == key) {//cur.data == key,時只有cur指針都在走,因為要遍歷刪除數據prev.next = cur.next;cur = cur.next;}else {//cur.data != key,兩個指針都在動,prev指針,指向cur指針prev = cur;cur = cur.next;}}// 3.注意最后不要漏了,head頭節點if (this.head.data == key) {this.head = this.head.next;}}

?三.鏈表部分相關oj面試題:(分享一些我認為比較重要的)
1.? 反轉一個單鏈表:我錄了視頻方便理解: 反轉一個鏈表-CSDN直播

反轉一個鏈表

class Solution {public ListNode reverseList(ListNode head) {ListNode cur = head;if(head == null) {return null;}head = null;while(cur != null) {ListNode curN = cur.next;cur.next = head;head = cur;cur = curN;}return head;}
}


2.給定一個帶有頭結點 head 的非空單鏈表,返回鏈表的中間結點。如果有兩個中間結點,則返回第二個中間結點:

理解視頻:找到鏈表中間節點-CSDN直播

找到鏈表中間節點

class Solution {public ListNode middleNode(ListNode head) {if(head == null) {return null;}ListNode fast = head;//快指針一次走2步ListNode slow = head;//慢指針一次走一步
//條件不可以交換:(fast != null && slow.next != null),fast可能開始就為nullwhile (fast != null && fast.next != null) {fast = fast.next.next;slow = slow.next;}return slow;}
}

3.將兩個有序鏈表合并為一個新的有序鏈表并返回。新鏈表是通過拼接給定的兩個鏈表的所有節點組成的:

理解視頻:合并兩個有序鏈表-CSDN直播

合并兩個有序鏈表


?

class Solution {public ListNode mergeTwoLists(ListNode list1, ListNode list2) {ListNode headH = new ListNode(-1);ListNode tmp = headH;//tmp用來遍歷兩個鏈表while(list1 != null && list2 != null) {//哪個節點數據小,就接在tmp后面if(list1.val < list2.val) {tmp.next = list1;list1 = list1.next;tmp = tmp.next;}else {tmp.next = list2;list2 = list2.next;tmp = tmp.next;}}//當其中一個鏈表遍歷完,就直接接上另一個鏈表的后半部分if(list1 != null) {tmp.next = list1;}if(list2 != null) {tmp.next = list2;}return headH.next;}
}

4.鏈表的回文結構:

這里有兩個點要注意:1.從后往前用slow走,因為偶數節點,fast指針會走到null,無法往前走

?2.回文時偶數情況下,A的下一個節點是slow節點,并且兩個節點的val相等。這個時候就要直接返回ture

理解視頻:鏈表的回文結構-CSDN直播

鏈表的回文結構

public class PalindromeList {public boolean chkPalindrome(ListNode A) {// write code hereif (A == null) {return true;}// write code hereListNode fast = A;ListNode slow = A;//1.找到中間節點while (fast != null && fast.next != null) {fast = fast.next.next;slow = slow.next;}//2.翻轉鏈表ListNode cur = slow.next;while (cur != null) {ListNode curN = cur.next;cur.next = slow;slow = cur;cur = curN;}//3.判斷回文//讓A往后走,slow往前走直到;A.val==slow.val//注意:回文時會有偶數情況下,A的下一個節點是slow節點,并且兩個節點的val相等。這個時候就要直接返回turewhile (A != slow) {if (A.val != slow.val) {return false;}//到這里A.val == slow.val//A.val == slow.val前提下,偶數情況下,A的下一個節點是slow節點,并且兩個節點的val相等。這個時候就要直接返回tureif (A.next == slow) {return true;}A = A.next;slow = slow.next;}return true;}
}


?

5.編寫代碼,以給定值x為基準將鏈表分割成兩部分,所有小于x的結點排在大于或等于x的結點之前:

注意:這里我的方法是,改完后,鏈表數據從小到大的,而做題在牛客網是,要求反過來(但是方法都一樣)

理解視頻:鏈表分割-CSDN直播

鏈表分割

//鏈表的分割public Node partition(Node pHead, int x) {Node as = null;Node ae = null;Node bs = null;Node be = null;Node cur = pHead;while (cur != null) {if (cur.data > x) {//第一次插入if (as == null) {as = ae = cur;}else {//第N次插入ae.next = cur;ae = ae.next;}} else {//第一次插入if (bs == null) {bs = be = cur;}else{//第N次插入be.next = cur;be = be.next;}}cur = cur.next;}//當一個鏈表為空時,返回if(as == null) {return bs;}//如果到這里as!= null//連接兩部分ae.next = bs;//注意,第二部分結尾不為空時,要手動把第二部分最后一個節點,手動制空if(bs != null) {be.next = null;}//最后返回asreturn bs;}

6.給定一個鏈表,返回鏈表開始入環的第一個節點。 如果鏈表無環返回空 :

方法是:第一次相遇點,到入口點的距離,等于起始點到入口點的距離

這里我畫了這個圖的推到:

public class Solution {public ListNode detectCycle(ListNode head) {ListNode fast = head;ListNode slow = head;//  方法:第一次相遇點,到入口點的距離,等于起始點到入口點的距離while(fast != null && fast.next != null) {fast = fast.next.next;slow = slow.next;if(fast == slow) {break;}}/**1.走到這里,要么不滿足{(fast != null && fast.next != null)}就是沒有環;2. 要么就是有環*///沒有環if(fast == null || fast.next == null) {return null;}/**有環:讓slow以和fast以相同的速度,從起始點到入口點,fast從第一次相遇的成環點走到入口點*/slow = head;//把slow返回起始點while(slow != fast) {slow = slow.next;fast = fast.next;}return slow;}
}


7.輸入兩個鏈表,找出它們的第一個公共結點:

方法:先找到哪個鏈表長,再讓長的鏈表他們的差值步最后兩個鏈表一起走,直到他們第一次相遇。

public class Solution {public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {//1.先分別求出兩個鏈表的長度ListNode pl = pHead1;ListNode ps = pHead2;int lenA = 0;int lenB = 0;while (pl != null) {lenA++;pl = pl.next;}while (ps != null) {lenB++;ps = ps.next;}//注意pl和ps,指向了null,要賦值回來pl = pHead1;ps = pHead2;//2.求差值int len = lenA - lenB;if (len < 0) {pl = pHead2;ps = pHead1;len = lenB - lenA;//len變為為正數}//現在知道pl指向長的鏈表,ps指向短的鏈表//3.操作兩個鏈表pl和ps,長的鏈表(pl)先走鏈表的差值,然后再一起走直到相交while (len != 0) {pl = pl.next;len--;}//兩個鏈表分別都走,直到他們相遇while (pl != ps) {pl = pl.next;ps = ps.next;}if (pl == null) {//pl,ps為空,也不可能相交return null;}return pl;}
}


?

?四.LinkedList的模擬實現:無頭雙向鏈表實現
?
1.寫的類和包:
其實 無頭雙向鏈表,就比單鏈表多了一個,可以指向前一個節點的引用域,并且尾節點也被一個引用記錄著。這樣任意位置插入就不用記錄節點了。
2.實現:
這里注意一下刪除雙鏈表指定位置Remove的節點 :可以優化一下代碼,先刪除頭節點,之后尾節點和中間任意位置節點,有重復代碼,(cur.prev.next = cur.next)可以共用;
public class MyLinkList implements  IList{static class ListNode{public int val;public ListNode prev;public ListNode next;public ListNode(int val) {this.val = val;}}public ListNode head;//頭節點public ListNode last;//尾節點@Overridepublic void addFirst(int data) {ListNode node = new ListNode(data);if (head == null) {head = last = node;}else {//所有的插入優先綁定后面node.next = head;head.prev = node;head = node;}}@Overridepublic void addLast(int data) {ListNode node = new ListNode(data);if (head == null) {head = last = node;}else {last.next = node;node.prev = last;last = last.next;}}@Overridepublic void addIndex(int index, int data) {int len = size();if (index > len || index < 0) {return;}if (index == len) {addLast(data);}if (index == 0) {addFirst(data);}ListNode cur = findIndex(index);ListNode node = new ListNode(data);node.next = cur;cur.prev.next = node;node.prev = cur.prev;cur.prev = node;}private ListNode findIndex(int index) {ListNode cur = head;while (index != 0) {cur = cur.next;index--;}return cur;}@Overridepublic boolean contains(int key) {ListNode cur = head;while (cur != null) {if (cur.val == key) {return true;}cur = cur.next;}return false;}@Overridepublic void remove(int key) {ListNode cur = head;while (cur != null) {if (cur.val == key) {if (cur == head) {//當只有一個節點要刪除時if (head == null) {cur.next.prev = null;}head = head.next;//刪除就走人return;}else {cur.prev.next = cur.next;//優化后,刪除中間和尾巴的代碼if (cur == last) {last = cur.prev;}else {cur.next.prev = cur.prev;}//刪除就走人return;}}cur = cur.next;}}@Overridepublic void removeAllKey(int key) {ListNode cur = head;while (cur != null) {if (cur.val == key) {if (cur == head) {//當只有一個節點要刪除時,cur.next.prev = null會為空,所以加上if判斷if (head == null) {cur.next.prev = null;}head = head.next;//刪除不能走人,接著刪除后面。}else {cur.prev.next = cur.next;//優化后,刪除中間和尾巴的代碼if (cur == last) {last = cur.prev;}else {cur.next.prev = cur.prev;}//刪除不能走人,接著刪除后面。}}cur = cur.next;}}@Overridepublic int size() {ListNode cur = head;int len = 0;while (cur != null) {len++;cur = cur.next;}return len;}@Overridepublic void display() {ListNode cur = head;while (cur != null) {System.out.print(cur.val + " ");cur = cur.next;}System.out.println();}@Overridepublic void clear() {ListNode cur = head;while (cur != null) {ListNode curN = cur.next;cur.next = null;cur.prev = null;cur = curN;}//注意head和last節點在鏈表中還被引用著head = last = null;}
}

五.LinkedList的使用:
1.什么是LinkedList:
LinkedList的底層是雙向鏈表結構,由于鏈表沒有將元素存儲在連續的空間中,元素存儲在單獨的節點中,然后通過引用將節點連接起來了,因此在在任意位置插入或者刪除元素時,不需要搬移元素,效率比較高。
2.? 在集合框架中,LinkedList也實現了List接口,具體如下:

總結
1. LinkedList實現了List接口
2. LinkedList的底層使用了雙向鏈表
3. LinkedList沒有實現RandomAccess接口,因此LinkedList不支持隨機訪問
4. LinkedList的任意位置插入和刪除元素時效率比較高,時間復雜度為O(1)
5. LinkedList比較適合任意位置插入的場景

?
3. LinkedList也有有參數和二無參數的構造方法:
4.方法的使用表參考:
public class Test {public static void main(String[] args) {List<Integer> list = new LinkedList<>();list.add(1);list.add(2);list.add(3);list.add(4);System.out.println(list);ArrayList<Integer> list1 = new ArrayList<>();list1.add(11);list1.add(12);list1.add(13);System.out.println("==============");list.addAll(list1);System.out.println(list);}
}

輸出:

5.LinkedList的遍歷:ListIteratorIterator的一個子類,可以專門用來打印鏈表

代碼如下:

public class Test {public static void main(String[] args) {List<Integer> list = new LinkedList<>();list.add(1);list.add(2);list.add(3);list.add(4);System.out.println(list);ArrayList<Integer> list1 = new ArrayList<>();list1.add(11);list1.add(12);list1.add(13);System.out.println("foreach遍歷");for (Integer x:list) {System.out.print(x + " ");}System.out.println();System.out.println("迭代器遍歷歷");Iterator<Integer> it = list.iterator();while (it.hasNext()) {System.out.print(it.next() + " ");}/*** ListIterator是Iterator的一個子類,可以專門用來打印鏈表*/System.out.println();System.out.println("使用迭代器遍歷---正向遍歷");ListIterator<Integer> it1 = list.listIterator();while (it1.hasNext()) {System.out.print(it1.next() + " ");}System.out.println();System.out.println("使用反向迭代器---反向遍歷");ListIterator<Integer> it2 = list.listIterator(/*這里要傳鏈表的長度*/ list.size());while (it2.hasPrevious()) {System.out.print(it2.previous() + " ");}}
}


?

?六.ArrayList和LinkedList的區別:

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/46095.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/46095.shtml
英文地址,請注明出處:http://en.pswp.cn/web/46095.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

一些常見的網絡故障

&#x1f4d1;打牌 &#xff1a; da pai ge的個人主頁 &#x1f324;?個人專欄 &#xff1a; da pai ge的博客專欄 ??寶劍鋒從磨礪出&#xff0c;梅花香自苦寒來 ??運維工程師的職責&#xff1a;監…

【數據分析】Python數據分析實戰:從零開始構建數據管道

Python數據分析實戰&#xff1a;從零開始構建數據管道 引言一、數據獲取二、數據清洗三、數據分析四、數據可視化五、案例研究&#xff1a;預測股票價格結論 我嘗試訪問您所提供的鏈接&#xff0c;但似乎該鏈接指向的內容已失效或被移除&#xff0c;因此無法直接獲取并閱讀該文…

【iOS】——ARC源碼探究

一、ARC介紹 ARC的全稱Auto Reference Counting. 也就是自動引用計數。使用MRC時開發者不得不花大量的時間在內存管理上&#xff0c;并且容易出現內存泄漏或者release一個已被釋放的對象&#xff0c;導致crash。后來&#xff0c;Apple引入了ARC。使用ARC&#xff0c;開發者不再…

BUUCTF逆向wp [HDCTF2019]Maze

第一步 查殼&#xff0c;本題是32位&#xff0c;有殼&#xff0c;進行脫殼。 第二步 這里的 jnz 指令會實現一個跳轉&#xff0c;并且下面的0EC85D78Bh被標紅了&#xff0c;應該是一個不存在的地址&#xff0c;這些東西就會導致IDA無法正常反匯編出原始代碼&#xff0c;也稱…

中文科技核心論文發表

中文科技核心論文題目如下&#xff1a; 1.混凝土結構用纖維增強塑料筋的耐久性評述&#xff1a;適合建筑、結構、材料等專業 2.建筑工程用阻燃塑料的研究進展&#xff1a;適合建筑、材料專業 3.纖維增強熱塑性塑料在面部護具中的應用研究&#xff1a;適合化工、醫學、材料等專…

springcloud2021.x使用nacos做配置中心

spirngcloud2021.0.5使用nacos做配置中心遇到的問題 環境 jdk1.8&#xff0c;spring-boot 2.6.13&#xff0c;spring-cloud-alibaba 2021.0.5.0 &#xff0c;spring-cloud 2021.0.5 方案一 application.properties # Nacos幫助文檔: https://nacos.io/zh-cn/docs/concepts…

C++中的condition_variable:條件變量

理解 C 中的條件變量&#xff08;Condition Variable&#xff09; 在多線程編程中&#xff0c;我們常常需要一個線程等待某個條件的變化&#xff0c;比如等待數據的生成或某個標志位的設置。如果沒有條件變量&#xff08;condition_variable&#xff09;&#xff0c;線程可能會…

啟智暢想火車類集裝箱號碼識別技術,軟硬件解決方案

集裝箱號碼識別需求&#xff1a; 實時檢測車皮號、火車底盤號碼、集裝箱號碼&#xff0c;根據火車類型分為以下三種情況&#xff1a; 1、純車皮&#xff0c;只檢測車皮號&#xff1b; 2、火車拉貨箱&#xff08;半車皮&#xff09;&#xff0c;檢測車皮號集裝箱號碼&#xff1b…

如何從0搭建一個Ai智體day01

&#x1f4da;《AI破局行動&#xff5c;AI智能體&#xff08;coze&#xff09;實戰手冊》&#xff1a; https://d16rg8unadx.feishu.cn/wiki/XQESwHW5HiPFlrkZbkqc0Xp7nEb 說明 這個是授權訪問的&#xff0c;想學習加我 微信/ Github:** watchpoints &#x1f4fa;Day1-大圣直播…

玩轉HarmonyOS NEXT之常用布局三

輪播&#xff08;Swiper&#xff09; Swiper組件提供滑動輪播顯示的能力。Swiper本身是一個容器組件&#xff0c;當設置了多個子組件后&#xff0c;可以對這些子組件進行輪播顯示。通常&#xff0c;在一些應用首頁顯示推薦的內容時&#xff0c;需要用到輪播顯示的能力。 針對…

git開發流程

分支介紹 master - 主分支 所有提供給用戶使用的正式版本&#xff0c;都在這個主分支上發布 開發者在此分支 不可進行 push 操作 dev - 開發分支 日常開發所使用的分支&#xff0c;開發者完成的階段性功能模塊將首先被合并到此分支 此分支亦是團隊內部測試、階段性工作驗證…

Xcode 16 beta3 真機調試找不到 Apple Watch 的嘗試解決

很多小伙伴們想用 Xcode 在 Apple Watch 真機上調試運行 App 時卻發現&#xff1a;在 Xcode 設備管理器中壓根找不到對應的 Apple Watch 設備。 大家是否已將 Apple Watch 和 Mac 都重啟一萬多遍了&#xff0c;還是束手無策。 Apple Watch not showing in XCodeApple Watch wo…

C++基礎語法:STL之容器(1)--容器概述和序列概述

前言 "打牢基礎,萬事不愁" .C的基礎語法的學習 引入 STL是標準模板庫,類模板主要是用來做容器的,所以個人理解:標準模板庫是"標準容器庫".容器是STL的核心 .以<C Prime Plus> 6th Edition(以下稱"本書")內容理解容器. 類模板內容回顧 類…

NineData全面支持PostgreSQL可視化表結構設計

“PostgreSQL 是最像 Oracle 的開源關系型數據庫“&#xff0c;也正因為如此&#xff0c;很多企業都青睞 PostgreSQL&#xff0c;拿它當成 Oracle 的替代品。所以毫無疑問&#xff0c;目前 PostgreSQL 在企業中非常常見。 對于直接接觸 PostgreSQL 的開發人員而言&#xff0c;…

echarts多柱堆疊的X軸順序

在一些圖表場景中&#xff0c;需要顯示多柱堆疊的數據&#xff0c;那么X軸上每一段單位區域內會有多根柱子&#xff0c;每一根柱子標識不同的數量項含義&#xff0c;那么怎樣控制這幾根柱的左右順序呢&#xff1f; 其實這跟echarts的option里的series由關&#xff0c;開始我以為…

快速排序及歸并排序的實現與排序的穩定性

目錄 快速排序 一. 快速排序遞歸的實現方法 1. 左右指針法 步驟思路 為什么要讓end先走&#xff1f; 2. 挖坑法 步驟思路 3. 前后指針法 步驟思路 二. 快速排序的時間和空間復雜度 1. 時間復雜度 2. 空間復雜度 三. 快速排序的優化方法 1. 三數取中優化 2. 小區…

實驗豐富、原創改進!|多策略改進蜣螂優化算法(MATLAB)

本文內容來源于本人公眾號&#xff1a;KAU的云實驗臺&#xff0c;更新內容&#xff1a;智能優化算法及其改進應用。 本文核心內容&#xff1a; 新穎的多策略改進蜣螂優化算法 對比算法包括&#xff1a;高引用/新發布/經典/其他DBO變體&#xff08;共11種&#xff09; 實驗設計…

用c語言寫一個貪吃蛇游戲

貪吃蛇游戲通常涉及到終端圖形編程和簡單的游戲邏輯。以下是一個基本的實現示例&#xff0c;包括貪吃蛇的移動、食物生成、碰撞檢測等功能。 1. 貪吃蛇游戲的基本結構 貪吃蛇游戲可以分為以下幾個部分&#xff1a; 游戲地圖和終端繪制&#xff1a;使用二維數組表示游戲地圖&am…

SpringBoot結合ip2region實現博客評論顯示IP屬地

你好呀&#xff0c;我是小鄒。 在現代的Web應用中&#xff0c;特別是博客和論壇類網站&#xff0c;為用戶提供地理定位服務&#xff08;如顯示用戶所在地理位置&#xff09;可以極大地增強用戶體驗。本文將詳細探討如何使用Java和相關技術棧來實現在博客評論中顯示用戶的地址信…

Java實驗3

實驗內容 學生信息管理系統 學生成績表Student(Sno 字符串&#xff0c;長度9, Sname 字符串&#xff0c;長度10, Class 字符串&#xff0c;長度10, Age 整型, Sex 字符串&#xff0c;長度2) 實現如下功能&#xff1a; A&#xff0e;輸入若干個學生的信息到Student表&#x…