算法-常見數據結構設計

文章目錄

    • 1. 帶有setAll功能的哈希表
    • 2. LRU緩存結構
    • 3. O(1)時間插入刪除隨機(去重)
    • 4. O(1)時間插入刪除隨機(不去重)
    • 5. 快速獲取數據流中的中位數
    • 6. 最大頻率棧
    • 7. 全O(1)結構
    • 8. LFU緩存結構

本節的內容比較難, 大多是leetcodeHard難度級別的題目

1. 帶有setAll功能的哈希表

哈希表常見的三個操作時put、get和containsKey,而且這三個操作的時間復雜度為O(1)。現在想加一個setAll功能,就是把所有記錄value都設成統一的值。請設計并實現這種有setAll功能的哈希表,并且put、get、containsKey和setAll四個操作的時間復雜度都為O(1)。

在這里插入圖片描述

思路分析 :
原始的哈希表的put,get,containsKey方法的時間復雜度都是O(1), 現在我們需要添加一個setAll方法, 把表中所有元素的值都改為一個特定的value,顯然直接遍歷的時間復雜度肯定不是O(1)
為了做到時間復雜度是O(1)我們采用時間戳計數的方法
給定一個屬性time記錄下本次操作的時間節點, 然后給定一個屬性是setAllValue和setAllTime,記錄下來我們的setAll調用時候是時間節點和設置的變量, 然后get方法返回的時候如果是大于該節點我們就進行返回原有的值, 如果小于該節點, 我們就返回setAllValue的值
代碼實現如下…


/*** 下面這個高頻的數據結構是帶有setAll功能的HashMap實現* 原理就是傳入一個時間戳, 然后進行模擬的判斷*/
class HashMapConSetAll {//基礎的HashMap結構private HashMap<Integer, int[]> map = new HashMap<>();//定義一個時間戳private int time = 0;//定義一個是用setAll方法的時間節點以及相關的值private int setAllValue = 0;private int setAllTime = -1;//給一個無參的構造方法public HashMapConSetAll() {}//我們實現的特殊HashMap的put方法public void put(int key, int value) {if (!map.containsKey(key)) {map.put(key, new int[]{value, time++});} else {int[] temp = map.get(key);temp[0] = value;temp[1] = time++;}}//我們實現的特殊的HashMap的get方法public int get(int key) {if (!map.containsKey(key)) {return -1;}//代碼執行到這里說明我們的map里面沒有這個元素int[] temp = map.get(key);if (temp[1] > setAllTime) {return temp[0];} else {return setAllValue;}}//特殊的containsKey方法public boolean containsKey(int key) {return map.containsKey(key);}//最重要的setAll方法public void setAll(int value) {this.setAllTime = time++;this.setAllValue = value;}
}

2. LRU緩存結構

在這里插入圖片描述

該數據結構的實現借助的是哈希表加上雙向鏈表的方式, 我們定義一個節點類Node, 里面的基礎屬性就是key與val, 我們的哈希表中的key就是節點中的key,我們的val就是該節點的地址, 為什么要用節點的地址作為val其實也非常的好理解, 用Node作為地址我們可以直接找到這個節點的位置然后進行操作,下面是我們的代碼實現


/*** LRU緩存結構* 實現的方法就是雙向鏈表 + 哈希表, 可以直接通過哈希表在O(1)的時間復雜度下獲取到位置節點的地址* 手寫一個雙向鏈表就行了*/
class LRUCache {// 首先定義的是雙向鏈表的節點類public static class Node {int key;int val;Node prev;Node next;public Node(int key, int val) {this.key = key;this.val = val;}}// 雙向鏈表的實現方式public static class DoubleLinkedList {// 鏈表的頭部(代表的是最早操作的數據)public Node first;// 鏈表的尾部(代表的是最新操作的數據)public Node last;// 給一個無參數的構造方法public DoubleLinkedList() {first = null;last = null;}// 添加節點的方法public void addNode(Node node) {if (node == null) {return;}if (first == null && last == null) {first = node;last = node;return;}last.next = node;node.prev = last;last = node;}//重構一下remove()和removeToLast()方法public Node remove() {//沒節點你刪除個damn啊if (first == null && last == null) {return null;}//只有一個節點的情況Node node = first;if (first == last) {last = null;first = null;} else {Node next = first.next;first.next = null;first = next;next.prev = null;}return node;}//下面是重構的removeToLast方法public void removeToLast(Node node) {//首先排除掉特殊的情況if (node == null || first == null) {return;}//如果只有一個的話或者是尾巴節點if (first == last || node == last) {return;}//如果是頭節點的節點 / 普通的節點if (node == first) {Node next = node.next;node.next = null;first = next;first.prev = null;} else {node.prev.next = node.next;node.next.prev = node.prev;node.prev = null;node.next = null;}//此時node節點完全是一個獨立的節點last.next = node;node.prev = last;last = node;}}private HashMap<Integer, Node> map = new HashMap<>();DoubleLinkedList list = new DoubleLinkedList();private int capacity;public LRUCache(int capacity) {this.capacity = capacity;}public int get(int key) {if (!map.containsKey(key)) {return -1;}Node node = map.get(key);list.removeToLast(node);return node.val;}public void put(int key, int value) {if (map.containsKey(key)) {Node node = map.get(key);node.val = value;list.removeToLast(node);} else {Node node = new Node(key, value);if (map.size() < capacity) {map.put(key, node);list.addNode(node);} else {Node nde = list.remove();map.remove(nde.key);list.addNode(node);map.put(key, node);}}}public static void main(String[] args) {LRUCache lruCache = new LRUCache(2);lruCache.put(1, 0);lruCache.put(2, 2);int res = lruCache.get(1);lruCache.put(3, 3);int res1 = lruCache.get(2);lruCache.put(4, 4);int res2 = lruCache.get(1);int res3 = lruCache.get(3);int res4 = lruCache.get(4);}
}

3. O(1)時間插入刪除隨機(去重)

在這里插入圖片描述

這個類的實現還是基于的哈希表, 外加上一個動態數組, key就是該數字, val是在動態數組里面的下標的位置, 如果刪除元素, 動態數組中的那個空位置我們就用最后一個元素去填充, 然后刪掉最后一個游戲(這樣就保證了這個時間的復雜度O(1)), 同時在哈希表里面刪除該值, 并該變最后一個元素的val為刪除元素的之前的下標, 代碼實現如下

class RandomizedSet {//其實現的方式是通過動態數組也就是我們的ArrayList跟HashMap共同實現的//其實從我們的經驗可以了解到, 凡是涉及到O(1)的操作一般都是通過散列表的形式實現的HashMap<Integer, Integer> map = new HashMap<>();ArrayList<Integer> list = new ArrayList<>();//構造方法這里其實沒什么用, 我們直接設置為空方法體的public RandomizedSet() {}//常規的insert方法, 我們的map結構第一個整數存儲的就是值, 第二個是下標public boolean insert(int val) {if (!map.containsKey(val)) {list.add(val);map.put(val, list.size() - 1);return true;}return false;}//remove方法是一個比較重要的方法public boolean remove(int val) {if (map.containsKey(val)) {int valIndex = map.get(val);int endValue = list.get(list.size() - 1);map.put(endValue, valIndex);list.set(valIndex, endValue);map.remove(val);list.remove(list.size() - 1);return true;}return false;}public int getRandom() {int randIndex = (int) (Math.random() * list.size());return list.get(randIndex);}public static void main1(String[] args) {RandomizedSet randomizedSet = new RandomizedSet();randomizedSet.remove(0);randomizedSet.remove(0);randomizedSet.insert(0);int res = randomizedSet.getRandom();randomizedSet.remove(0);randomizedSet.insert(0);}
}

4. O(1)時間插入刪除隨機(不去重)

在這里插入圖片描述

這個題目跟上一個題目只有一個不一樣的地方就是這個哈希表的val是我們的HashSet,也就是一個下標集合, 我們進行元素刪除的時候我們就隨意選擇一個待刪除元素的下標進行刪除即可, 我們的getRandom方法是用動態順序表的數據進行返回的, 所以自帶加權的功能, 代碼實現如下

class RandomizedCollection {// 這個其實原來的HashMap中的value不再是整數, 而是一個HashSet集合ArrayList<Integer> arr = new ArrayList<>();HashMap<Integer, HashSet<Integer>> map = new HashMap<>();public RandomizedCollection() {}//insert方法是比較簡單的, 就是直接放入元素即可public boolean insert(int val) {HashSet<Integer> set = map.get(val);if(set == null){HashSet<Integer> tempSet = new HashSet<>();tempSet.add(arr.size());map.put(val,tempSet);arr.add(val);return true;}else{set.add(arr.size());arr.add(val);return false;}}public boolean remove(int val) {HashSet<Integer> set = map.get(val);if(set == null){return false;}int indexValue = set.iterator().next();int swapValue = arr.get(arr.size() - 1);int swapIndex = arr.size() - 1;if(swapValue == val){arr.remove(arr.size() - 1);set.remove(arr.size());}else{HashSet<Integer> end = map.get(swapValue);end.remove(swapIndex);end.add(indexValue);set.remove(indexValue);arr.set(indexValue,swapValue);arr.remove(swapIndex);}if(set.size() == 0){map.remove(val);}return true;}public int getRandom() {return arr.get((int) (Math.random() * arr.size()));}
}/*** Your RandomizedCollection object will be instantiated and called as such:* RandomizedCollection obj = new RandomizedCollection();* boolean param_1 = obj.insert(val);* boolean param_2 = obj.remove(val);* int param_3 = obj.getRandom();*/

5. 快速獲取數據流中的中位數

在這里插入圖片描述

該數據結構的實現就是通過我們的堆結構來實現的, 建立一個大根堆來裝入小半部分的數據, 建立一個小根堆來建立大半部分的數據, 記住在裝入數據的過程中我們要保持我們的堆中的元素的大小, 也就是通過一個balance方法, 來保持兩邊的數量差值不超過1, 獲取中位數的時候我們, 如果兩邊數量不一致, 就返回多的哪一方的堆頂, 如果一致, 我們就返回兩個堆頂的平均值, 代碼實現如下

class MedianFinder {private PriorityQueue<Integer> maxHeap = new PriorityQueue<>(new Comparator<Integer>() {@Overridepublic int compare(Integer o1, Integer o2) {return o2 - o1;}});// 默認就是小根堆private PriorityQueue<Integer> minHeap = new PriorityQueue<>();public MedianFinder() {}public void addNum(int num) {if (maxHeap.isEmpty() || num < maxHeap.peek()) {maxHeap.offer(num);} else {minHeap.offer(num);}balance();}public double findMedian() {if (minHeap.size() == maxHeap.size()) {return (minHeap.peek() + maxHeap.peek()) / 2.0;} else if (maxHeap.size() < minHeap.size()) {return minHeap.peek();} else {return maxHeap.peek();}}// 平衡堆結構的方法private void balance() {if (Math.abs(minHeap.size() - maxHeap.size()) == 2) {if (minHeap.size() - maxHeap.size() == 2) {maxHeap.offer(minHeap.poll());} else {minHeap.offer(maxHeap.poll());}}}
}/*** Your MedianFinder object will be instantiated and called as such:* MedianFinder obj = new MedianFinder();* obj.addNum(num);* double param_2 = obj.findMedian();

6. 最大頻率棧

在這里插入圖片描述

這道題目的思路就是用兩個哈希表, 第一個哈希表存儲的是詞頻統計, 第二個哈希表是一個類似桶的結構, key就是出現的詞頻, val是一個動態的順序表, 代碼實現如下

class FreqStack {//本質就是通過哈希來模擬//哈希表的key是詞頻統計, val是一個動態的順序表, 里面存放這該詞頻的數字HashMap<Integer,ArrayList<Integer>> map = new HashMap<>();//再創建一個哈希表用于詞頻的統計HashMap<Integer,Integer> frq = new HashMap<>();//最大的詞頻(用于pop()操作指示)private int maxFrq = 0;public FreqStack() {//構造方法里面不寫東西}public void push(int val){//首先進行詞頻的統計frq.put(val,frq.getOrDefault(val,0) + 1);maxFrq = Math.max(maxFrq,frq.get(val));ArrayList res = map.get(frq.get(val));if(res == null){ArrayList<Integer> arr = new ArrayList<>();arr.add(val);map.put(frq.get(val),arr);}else{res.add(val);}}//pop方法的時候應該進行的元素的刪除操作public int pop() {ArrayList<Integer> arr = map.get(maxFrq);if(arr.size() == 1){int temp = arr.remove(0);map.remove(maxFrq--);if(frq.get(temp) == 1){frq.remove(temp);}else{frq.put(temp,frq.get(temp) - 1);}return temp;}else{int temp = arr.remove(arr.size() - 1);if(frq.get(temp) == 1){frq.remove(temp);}else{frq.put(temp,frq.get(temp) - 1);}return temp;}}
}/*** Your FreqStack object will be instantiated and called as such:* FreqStack obj = new FreqStack();* obj.push(val);* int param_2 = obj.pop();*/

7. 全O(1)結構

在這里插入圖片描述

這個就是哈希表加上雙向鏈表桶的思路, 哈希表中保存的是該字符串的所在桶的地址, 桶里面存放的是該詞頻的字符串的情況, 代碼實現如下, 下面有一個LFU緩存也是這樣的一個結構, 雙向鏈表(桶), 桶里面再嵌套一個雙向鏈表實現的堆結構…

class RandomizedCollection {//這個其實原來的HashMap中的value不再是整數, 而是一個HashSet集合ArrayList<Integer> arr = new ArrayList<>();HashMap<Integer, HashSet<Integer>> map = new HashMap<>();public RandomizedCollection() {}//insert方法是比較簡單的, 就是直接放入元素即可public boolean insert(int val) {HashSet<Integer> set = map.get(val);if (set == null) {HashSet<Integer> tempSet = new HashSet<>();tempSet.add(arr.size());map.put(val, tempSet);arr.add(val);return true;} else {set.add(arr.size());arr.add(val);return false;}}public boolean remove(int val) {HashSet<Integer> set = map.get(val);if (set == null) {return false;}int indexValue = set.iterator().next();int swapValue = arr.get(arr.size() - 1);int swapIndex = arr.size() - 1;if (swapValue == val) {arr.remove(arr.size() - 1);set.remove(arr.size());} else {HashSet<Integer> end = map.get(swapValue);end.remove(swapIndex);end.add(indexValue);set.remove(indexValue);arr.set(indexValue, swapValue);arr.remove(swapIndex);}if (set.size() == 0) {map.remove(val);}return true;}public int getRandom() {return arr.get((int) (Math.random() * arr.size()));}public static void main(String[] args) {RandomizedCollection set = new RandomizedCollection();set.insert(1);set.remove(1);set.insert(1);}
}

8. LFU緩存結構


/*** LFU緩存 :* 1. 首先定義一個節點的對象, 里面保存的是該傳入數據的key和value(ListNode)* 這個東西也是一個雙向鏈表的結構(模擬隊列使用) --> 不可以用LinkedList(源碼的remove方法是遍歷刪除的結構)* 2. 其次我們定義一個桶結構, 里面有一個val用來保存操作的次數, 還有一個雙向的鏈表(也就是我們的上面定義的隊列結構)* 這個桶的結構也是類似于雙端的鏈表(模擬雙向鏈表使用)* 3. 然后我們需要定義兩個哈希表* 第一個HashMap中的val保存的是該數字的所在桶的地址(方便定位桶的位置進行操作)* 第二個HashMap中的val保存的是該數字本身的ListNode的地址(方便進行刪除操作)* 4. 返回使用量最小的元素就去最左邊的桶里面拿隊列中的first元素* 5. 桶的左右兩側我們定義了0操作次數, 以及Integer.MAX_VALUE桶, 減少了邊界位置的判斷*/class LFUCache {/*** 基礎的節點的元素定義*/static class Node {int key;int val;Node prev;Node next;public Node(int key, int val) {this.key = key;this.val = val;}}/*** 模擬的隊列的實現類*/static class MQueue {//屬性定義為這樣是為了和下面的桶結構區分開Node head;Node tail;int size;//無參數的構造方法public MQueue() {this.head = null;this.tail = null;}//remove方法用來移除掉指定位置的節點public Node remove(Node node) {if (head == null || tail == null) {throw new RuntimeException("沒有節點無法移動");}if (head == tail) {tail = null;head = null;} else if (node == this.head) {Node temp = this.head.next;this.head.next = null;this.head = temp;this.head.prev = null;} else if (node == tail) {Node temp = tail.prev;tail.prev = null;tail = temp;tail.next = null;} else {node.prev.next = node.next;node.next.prev = node.prev;node.next = null;node.prev = null;}size--;return node;}//下面是我們的pop方法public Node pop() {return remove(head);}//下面是我們的offer()方法public void offer(Node node) {if (head == null && tail == null) {head = node;tail = node;size++;return;}tail.next = node;node.prev = tail;tail = node;size++;}}/*** 下面我們要完成我們的桶結構的實現(桶結構的val是出現的次數, 桶結構里面有一個我們手寫的一個隊列結構)*/static class Bucket {//出現的頻率int time;//我們想要的隊列結構MQueue mQueue;//模擬雙向鏈表必須的實現Bucket prev;Bucket next;//構造方法public Bucket(int time) {this.time = time;mQueue = new MQueue();}}static class MBucket {//用作基石的兩個桶Bucket min = new Bucket(0);Bucket max = new Bucket(Integer.MAX_VALUE);public MBucket(){min.next = max;max.prev = min;}//桶的插入插入操作(cur是參照結構)public void insert(Bucket cur, Bucket pos) {cur.next.prev = pos;pos.next = cur.next;cur.next = pos;pos.prev = cur;}//桶的刪除操作public void remove(Bucket cur) {cur.prev.next = cur.next;cur.next.prev = cur.prev;}}//那個容量大小int capacity;//兩個重要的HashMap結構HashMap<Integer, Node> nodeIndexMap = new HashMap<>();HashMap<Integer, Bucket> bucketIndexMap = new HashMap<>();MBucket mBucket = new MBucket();public LFUCache(int capacity) {this.capacity = capacity;}public int get(int key) {if (!nodeIndexMap.containsKey(key)) {return -1;} else {Bucket curBucket = bucketIndexMap.get(key);Node curNode = nodeIndexMap.get(key);if (curBucket.next.time > curBucket.time + 1) {Bucket newBucket = new Bucket(curBucket.time + 1);mBucket.insert(curBucket, newBucket);curBucket.mQueue.remove(curNode);newBucket.mQueue.offer(curNode);} else {curBucket.mQueue.remove(curNode);curBucket.next.mQueue.offer(curNode);}bucketIndexMap.put(key, curBucket.next);//判斷先前的那個桶是不是空的(是空桶就刪掉)if (curBucket.mQueue.size == 0) {mBucket.remove(curBucket);}return curNode.val;}}public void put(int key, int value) {if (nodeIndexMap.containsKey(key)) {Node curNode = nodeIndexMap.get(key);Bucket curBucket = bucketIndexMap.get(key);curNode.val = value;if (curBucket.next.time > curBucket.time + 1) {Bucket newBucket = new Bucket(curBucket.time + 1);mBucket.insert(curBucket, newBucket);curBucket.mQueue.remove(curNode);newBucket.mQueue.offer(curNode);} else {curBucket.mQueue.remove(curNode);curBucket.next.mQueue.offer(curNode);}bucketIndexMap.put(key, curBucket.next);//判斷先前的那個桶是不是空的(是空桶就刪掉)if (curBucket.mQueue.size == 0) {mBucket.remove(curBucket);}} else {Node newNode = new Node(key, value);if (nodeIndexMap.size() < capacity) {if (mBucket.min.next.time != 1) {Bucket newBucket = new Bucket(1);newBucket.mQueue.offer(newNode);mBucket.insert(mBucket.min, newBucket);nodeIndexMap.put(key, newNode);bucketIndexMap.put(key, newBucket);} else {Bucket oneBucket = mBucket.min.next;oneBucket.mQueue.offer(newNode);nodeIndexMap.put(key, newNode);bucketIndexMap.put(key, oneBucket);}} else {Node removeNode = mBucket.min.next.mQueue.pop();nodeIndexMap.remove(removeNode.key);bucketIndexMap.remove(removeNode.key);if(mBucket.min.next.mQueue.size == 0){mBucket.remove(mBucket.min.next);}if(mBucket.min.next.time != 1){Bucket newBucket = new Bucket(1);newBucket.mQueue.offer(newNode);mBucket.insert(mBucket.min, newBucket);nodeIndexMap.put(key, newNode);bucketIndexMap.put(key, newBucket);}else{Bucket oneBucket = mBucket.min.next;oneBucket.mQueue.offer(newNode);nodeIndexMap.put(key, newNode);bucketIndexMap.put(key, oneBucket);}}}}public static void main(String[] args) {LFUCache lfu = new LFUCache(2);lfu.put(1,1);lfu.put(2,2);lfu.get(1);lfu.put(3,3);lfu.get(2);lfu.get(3);lfu.put(4,4);lfu.get(1);lfu.get(3);lfu.get(4);}
}

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

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

相關文章

js計算兩個日期直接的間隔天,2018/12/14到2017/11/10有多少天

const startDate new Date(2017-11-10)const endDate new Date(2018-12-14)const diffTime Math.abs(endDate - startDate)const diffDays Math.ceil(diffTime / (1000 * 60 * 60 * 24))console.log(diffDays) // 輸出天數差 人工智能學習網站 https://chat.xutongbao.top…

解析Java中1000個常用類:DoubleSummaryStatistics類,你學會了嗎?

在線工具站 推薦一個程序員在線工具站:程序員常用工具(http://cxytools.com),有時間戳、JSON格式化、文本對比、HASH生成、UUID生成等常用工具,效率加倍嘎嘎好用。程序員資料站 推薦一個程序員編程資料站:程序員的成長之路(http://cxyroad.com),收錄了一些列的技術教程…

VSCode神仙插件——Codeium (AI編程助手)

1、安裝&登錄插件 安裝過程中會讓你登錄Codeium賬戶&#xff0c;可以通過Google賬戶登錄&#xff0c;或者可以注冊一個Codeium賬戶&#xff08;如果沒有彈出讓你登錄賬戶的界面&#xff0c;可以等安裝結束后在右下角找到登錄的地方&#xff09; 右下角顯示如下圖所示&#…

【ubuntu中關于驅動得問題】—— 如何將nouveau驅動程序加入黑名單和安裝NVIDIA顯卡驅動

提示&#xff1a;文章寫完后&#xff0c;目錄可以自動生成&#xff0c;如何生成可參考右邊的幫助文檔 文章目錄 前言一、nouveau驅動程序加入黑名單二、安裝NVIDIA顯卡驅動總結 前言 NVIDIA顯卡驅動是用于支持和優化NVIDIA顯卡在計算機系統中運行的關鍵軟件組件。該驅動程序能…

【每日一練】python算數練習題(函數.隨機.判斷綜合運用)

""" 幼兒園加減法練習題 答對點贊表情&#xff0c;答錯炸彈表情 表情隨機出現 如果全答對有大獎 """ import random df0 #定義答對函數 def dd():global dfdf10bq["&#x1f339;&#x1f339;&#x1f339;","&#x1f389;&…

(接上一篇)前端弄一個變量實現點擊次數在前端頁面實時更新

實現點擊次數在前端頁面實時更新&#xff0c;確實需要在前端維護一個變量來存儲當前的點擊次數。這個變量通常在Vue組件的data選項中定義&#xff0c;并在組件的生命周期方法或事件處理函數中更新。 以下是實現這一功能的基本步驟&#xff1a; 定義變量&#xff1a;在Vue組件的…

系統測試-測試方法學習

目錄 &#xff08;1&#xff09;等價類 &#xff08;2&#xff09;邊界值 &#xff08;3&#xff09;正交&#xff1a;&#xff08;只用于確定排列組合&#xff0c;不確定具體內容&#xff09; (4)判定表法 &#xff08;5&#xff09;流程分析法 &#xff08;6&#xff0…

Django 查詢數據

模型參考上一章內容&#xff1a; Django QuerySet對象&#xff0c;filter()方法-CSDN博客 查詢數據可以通過以下方法&#xff1a; Book.objects.all() Book.objects.filter() Book.objects.get() 1&#xff0c;添加視圖函數 Test/app11/views.py from django.shortcuts im…

std::deque和std::list的區別是什么

std::deque&#xff08;雙端隊列&#xff09;和std::list&#xff08;雙向鏈表&#xff09;是C標準模板庫&#xff08;STL&#xff09;中兩種不同的序列容器&#xff0c;它們在內部實現、性能特性和使用場景上存在一些關鍵區別。以下是對這些區別的詳細分析&#xff1a; 1. 內…

vue3.0所采用的composition Api與vue2.x使用的Option Api有什么區別

Vue 3.0 引入了 Composition API&#xff0c;與 Vue 2.x 使用的 Options API 相比&#xff0c;有幾個重要的區別和優勢&#xff1a; 代碼組織方式&#xff1a; Options API&#xff08;Vue 2.x&#xff09;&#xff1a; 將相關功能的代碼組織在一個對象中&#xff08;如 data、…

昇思25天學習打卡營第12天|MindSpore-基于MobileNetv2的垃圾分類

基于MobileNetv2的垃圾分類 主要介紹垃圾分類代碼開發的方法。通過讀取本地圖像數據作為輸入,對圖像中的垃圾物體進行檢測,并且將檢測結果圖片保存到文件中。 1、實驗目的 了解熟悉垃圾分類應用代碼的編寫(Python語言);了解Linux操作系統的基本使用;掌握atc命令進行模型…

Spring學習05-[AOP學習-AOP原理和事務]

AOP原理和事務 AOPAOP底層原理比如下面的代碼案例手動模擬AOP 動態代理詳解JDK動態代理具體實現 AOP AOP底層原理 當實現了AOP,Spring會根據當前的bean創建動態代理(運行時生成一個代理類) 面試題&#xff1a;為什么執行方法的時候&#xff0c;會執行切面里的通知方法&#xf…

華為機試HJ40統計字符

華為機試HJ40統計字符 題目&#xff1a; 想法&#xff1a; 統計上述題目中的四種字符的個數存入字典中&#xff0c;按指定順序進行輸出 input_str input()str_dict {"alpha": 0, "space": 0, "number": 0, "others": 0}for i in …

ZYNQ-LINUX環境C語言利用Curl庫實現HTTP通訊

前言 在Zynq-Linux環境中&#xff0c;需要使用C語言來編寫APP時&#xff0c;訪問HTTP一般可以使用Curl庫來實現&#xff0c;但是在Zynq的SDK中&#xff0c;并沒有集成該庫&#xff0c;在尋找了很多資料后找到了一種使用很方便的額辦法。這篇文章主要記錄一下移植Curl的過程。 …

【2024_CUMCM】數據預處理、數據分析、數據可視化

目錄 2023-c題-問題1 問題分析 偏度 峰度 箱線圖 讀圖 重采樣、降采樣、升采樣 重采樣 降采樣 升采樣 解題代碼 2023-c題-問題1 問題分析 問題說白了就是探究品類和銷售量這兩個數據他們各自內在聯系&#xff0c;根據題意&#xff0c;我們先進行數 據預處理&#…

【C語言】 —— 編譯和鏈接

【C語言】 —— 編譯和鏈接 一、編譯環境和運行環境二、翻譯環境2.1、 預處理2.2、 編譯&#xff08;1&#xff09;詞法分析&#xff08;2&#xff09;語法分析&#xff08;3&#xff09;語義分析 2.3、 匯編2.4、鏈接 三、運行環境 一、編譯環境和運行環境 平時我們說寫 C語言…

C語言中32位浮點數的格式

以 GNU C為例&#xff0c;它遵循 IEEE 754-2008標準中制定的浮點表示規范。在該規范中定義了 5種不同大小的基礎二進制浮點格式&#xff0c;包括&#xff1a;16位&#xff0c;32位&#xff0c;64位&#xff0c;128位&#xff0c;256位。其中&#xff0c;32位的格式被用作標準 C…

使用AOP思想實現開閉原則下的流水日志輸出

主要實現思想&#xff1a; 通過實現Convert接口來抽取公共組件&#xff0c;獲取想要的標準模型。 現在有兩個訂單場景&#xff0c;一個保存訂單&#xff0c;一個為更新訂單。構造如下的服務類&#xff1a; import org.springframework.stereotype.Service;Service public clas…

JavaScript-實例-button

1 需求 2 接口 3 點擊button跳轉到一個頁面 在HTML中&#xff0c;當你想要點擊一個按鈕并跳轉到另一個頁面時&#xff0c;通常你可以使用<a>標簽來包裹按鈕的樣式&#xff08;盡管這通常不是最佳實踐&#xff0c;因為<a>標簽是用于鏈接的&#xff0c;而<button&…

SHAP(SHapley Additive exPlanations)基于XGBoost模型的可解釋機器學習

模型可解釋性 這是一個關于錯誤解釋機器學習模型的危險以及正確解釋它的價值的故事。如果您發現諸如梯度提升機或隨機森林之類的集成樹模型的魯棒準確性很有吸引力&#xff0c;但也需要解釋它們&#xff0c;那么我希望您發現這些信息有用且有幫助。 試想一下&#xff0c;我們…