主頁 > 後端開發 > Java堆疊[陣列,單鏈表],佇列【陣列,鏈表】和回圈佇列的實作

Java堆疊[陣列,單鏈表],佇列【陣列,鏈表】和回圈佇列的實作

2021-10-05 10:54:43 後端開發

1. 堆疊

1.1 概念

一種特殊的線性表,說明了具有前驅和后繼關系,只允許在固定的一端進行插入和洗掉元素操作,進行資料插入和洗掉的一端稱為堆疊頂,另一端稱為堆疊底,
堆疊中的資料元素遵循后進先出 LIFO 原則【Last In First Out】
壓堆疊:堆疊的插入/進堆疊/壓堆疊,入資料在堆疊頂
出堆疊:堆疊的洗掉操作叫做出堆疊,出資料也在堆疊頂
后進先出【類似于瀏覽器的回退,只會回傳上一個瀏覽后的頁面而不是回傳第一個打開的頁面;彈夾中的子彈】
在這里插入圖片描述
邪惡的小技巧:合理的出堆疊順序(畫堆疊圖)
已知一個堆疊的入堆疊序列是m, n, x, y, z.則不可能出現的出堆疊順序是: C
A mnxyz
B xnyzm
C nymxz
D nmyzx

A
在這里插入圖片描述
B
在這里插入圖片描述
C
在這里插入圖片描述

m要想出堆疊必須讓x出堆疊才行,所以是不可能的出堆疊順序

D
在這里插入圖片描述
邪惡的小技巧:中綴運算式轉后綴運算式
有一個中綴運算式為a*(b-(c+d)),它的后綴運算式可以是什么: A
A abcd+-*
B abc+d-*
C ab-cd+*
D abd+c-*

前綴運算式: 把運算子放前邊
中綴運算式:a*(b-(c+d)
后綴運算式: 把運算子放后邊

按照運算優先級給運算子號放在括號外邊

a*(b-(c+d))確定優先級
(a*(b-(c+d))) 打括號
+ 先算
(a*(b- ( cd )+ ))移動符號
(a* ( b(cd)+ )- )
( a(b(cd)+)- )*
后綴運算式: abcd+-*

這樣就不用像第一題那樣每次都畫操作堆疊
方法總結:從左往右,根據運算子的優先級(注意括號問題),額外加括號,把每個對應的運算子移到對應的括號外面,去除所有的括號,結果就是對應的前后綴運算式【后綴放后邊,前綴放前邊即可】

2*3(4+5)-6

(2*3(4+5)-6)
(2*3(45)+-6)
(2*(345)+*-6)
(2((345)+*)-6)
((2((345)+*)
)-6)
((2((345)+*)
)*6)-
2345 +**6-
在這里插入圖片描述
應用
int func(后綴運算式)

1.2 實作

public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(1);// 增加元素
        stack.push(2);
        stack.push(3);
        System.out.println(stack.peek());// 獲取堆疊頂元素但不洗掉 3
        System.out.println(stack.pop());// 彈出堆疊頂元素 洗掉3
        System.out.println(stack.peek());// 獲取堆疊頂元素但不洗掉2
        System.out.println(stack.empty());// 堆疊自帶的 empty 方法
        System.out.println(stack.isEmpty());// 繼承 vector 的方法
        System.out.println(stack.search(2));// 查找下標
        System.out.println(stack.search(3));// 沒有就回傳 -1
    }

3
3
2
false
false
1
-1

Stack 原始碼
在這里插入圖片描述

發現只有 push, peek, pop, empty, search 方法
為何可以使用 isEmpty 呢?

為何可以使用 isEmpty 方法呢,
在這里插入圖片描述

在這里插入圖片描述

因為 Stack 繼承 Vector,所以可以使用父類的 isEmpty方法
分析一下 push 壓堆疊操作,來查看它的底層是如何實作的
在這里插入圖片描述
查看 addElementr 方法
在這里插入圖片描述
如果不清楚源代碼內容的可以查看我的博客——List的使用中 add 方法一步步原始碼決議,了解堆疊的底層陣列如何擴容如何增加元素

我們查看一下 Stack 繼承和實作
在這里插入圖片描述
發現這個體系是:Stack 類繼承 Veator 類, Vector 類繼承 AbstractList 類, AbstractList 類繼承自 AbstractCollection 類, AbstractCollection 類實作 Collection 介面, Collection 介面繼承 Iterable 介面

1.2.1 陣列實作Stack

import java.util.Arrays;

public class MyStackList<E> {
//    public static void main1(String[] args) {
//        Stack<Integer> stack = new Stack<>();
//        stack.push(1);// 增加元素
//        stack.push(2);
//        stack.push(3);
//        System.out.println(stack.peek());// 獲取堆疊頂元素但不洗掉 3
//        System.out.println(stack.pop());// 彈出堆疊頂元素 洗掉3
//        System.out.println(stack.peek());// 獲取堆疊頂元素但不洗掉2
//        System.out.println(stack.empty());// 堆疊自帶的 empty 方法
//        System.out.println(stack.isEmpty());// 繼承 vector 的方法
//        System.out.println(stack.search(2));// 查找下標
//        System.out.println(stack.search(3));// 沒有就回傳 -1
//    }

    private E[] elem;
    private int usedSize = 0;
    private int capacity = 4;

    MyStackList() {
        this.elem = (E[]) new Object[capacity];
    }

    // 擴容
    private void checkCapacity() {
        if (this.usedSize == this.capacity) {
            this.capacity *= 2;
            this.elem = Arrays.copyOf(this.elem, this.capacity);
        }
    }

    E push(E e) {
        checkCapacity();
        this.elem[this.usedSize++] = e;
        return this.elem[this.usedSize - 1];
    }

    E pop() {
        if (this.usedSize == 0) {
            throw new ArrayIndexOutOfBoundsException("Stack is empty !!!");
        } else {
            return this.elem[--this.usedSize];
        }
    }

    E peek() {
        if (this.usedSize == 0) {
            return null;
        } else {
            return this.elem[this.usedSize - 1];
        }
    }

    boolean empty() {
        return this.usedSize == 0;
    }

    void display() {
        for (int i = this.usedSize-1; i >= 0; i--) {
            System.out.print(this.elem[i] + " ");
        }
        System.out.println();
    }

    private static void testPush() {
        MyStackList stack = new MyStackList();
        for (int i = 0; i < 10; i++) {
            System.out.print(stack.push(i) + " ");
        }
    }

    private static void testPop() {
        System.out.println("Push:");
        MyStackList stack = new MyStackList();
        for (int i = 0; i < 10; i++) {
            stack.push(i);
        }
        stack.display();

        System.out.println("Pop:");
        for (int i = 0; i < 15; i++) {
            System.out.print(stack.pop() + " ");
        }

        System.out.println("Residue: ");
        stack.display();
    }

    private static void testPeek() {
        MyStackList stack = new MyStackList();
        System.out.println("Push:");
        for (int i = 0; i < 10; i++) {
            stack.push(i);
        }
        stack.display();

        System.out.println("Peek:");
        for (int i = 5; i < 10; i++) {
            System.out.print(stack.peek() + " ");
        }

        System.out.println("Residue:");
        stack.display();
    }

    public static void main(String[] args) {
    	// 放置測驗用例
        testPop();
    }
}

陣列實作堆疊, 為了提高效率該如何插入洗掉資料呢?

  1. 尾插尾刪: 避免了陣列元素的移動, 時間復雜度O(1)
  2. 頭插頭刪: 還要移動資料, 時間復雜度O(N)

1.2.2 單鏈表實作Stack

class Node<E> {
    private E val;
    private Node next;

    public Node(E val) {
        this.val = val;
    }

    Node head;

    E push(E val) {
        Node node = new Node(val);
        if (head == null) {
            head = node;
            return (E) head.val;
        } else {
            node.next = head;
            head = node;
            return (E) head.val;
        }
    }

    E pop() {
        if (head == null) {
            throw new NullPointerException("NULL !!!");
        } else {
            E ret = (E) head.val;
            head = head.next;
            return ret;
        }
    }

    E peek() {
        if (head == null) {
            throw new NullPointerException("NULL !!!");
        } else {
            return (E) head.val;
        }
    }

    void display() {
        Node cur = this.head;
        while (cur != null) {
            System.out.print(cur.val + " ");
            cur = cur.next;
        }
    }
}

public class MyStackLinked<E> {
    private static void testPush() {
        Node node = new Node(null);
        for (int i = 0; i < 8; i++) {
            System.out.print(node.push(i) + " ");
        }
    }

    private static void testPop() {
        Node node = new Node(null);
        for (int i = 0; i < 8; i++) {
            node.push(i);
        }
        for (int i = 0; i < 5; i++) {
            System.out.print(node.pop() + " ");
        }
    }

    private static void testPeek() {
        Node node = new Node(null);
        for (int i = 0; i < 8; i++) {
            node.push(i);
        }
        for (int i = 0; i < 5; i++) {
            System.out.print(node.peek() + " ");
        }
    }

    public static void main(String[] args) {
        testPeek();
    }
}

單鏈表實作堆疊, 為了提高效率該如何插入洗掉資料呢?

  1. 頭插頭刪: 時間復雜度O(1)
  2. 尾插尾刪: 不帶尾節點單鏈表時間是復雜度O(N);帶尾節點尾結點 tail 可以把入堆疊push操作的時間復雜度降到O(1)但是無法把出堆疊pop時間復雜度降到O(1)【需要找尾節點的前一個節點,所以是O(N)】

2. 佇列

2.1 概念

只允許一端進行資料插入操作,另一端進行資料洗掉操作的特殊線性表.佇列具有先進先出功能FIFO(First In First Out)
入佇列: 進行插入操作的一端稱為隊尾
出佇列: 進行洗掉操作的一端稱為對頭
在這里插入圖片描述
先進先出【作業系統的程式點開執行順序,客服電話,鍵盤的輸入,記事本的輸出】

2.2 實作

在這里插入圖片描述
發現 Queue 只有方框中的方法
Queue 介面繼承了 Collection 介面, Collection 介面繼承 Iterable 介面【實作程序比 Stack 簡單許多】

陣列實作Queue
陣列實作佇列有沒有什么問題呢?
因為是先進先出的, 所以會導致先出空間的內容造成浪費,而不是像堆疊那樣一直處于一端操作,不會造成空間浪費,如果元素移動的話來決解空間問題的話,時間復雜度會變為O(N)效率太低
在這里插入圖片描述
因此陣列的話可以通過“回圈”的方式實作佇列
什么是“回圈佇列”呢?
在這里插入圖片描述
分析解釋環形圖

  1. 0~7: 陣列的參考
  2. 11, 12, 13, 14, 15, 16, 17存盤的元素值
  3. rear:指向插入元素的參考【帶插入元素的下一個索引】,圖中代表的是剛插入元素17還未移動rear下標,此時插入元素操作完畢后的rear應該移動到下一個索引0處
  4. front:指向對頭元素的索引,每次出佇列一個元素就移動一次front

思考: 何時代表佇列滿了, 何時代表佇列空?

  1. front==rear 的時候,有兩種可能: 要么佇列滿要么佇列空
  2. 如果 rear 的下一個是 front 就代表滿了【現在可以區front==rear】的兩種情況了

思考: rear走到陣列末尾,該如何跳轉到陣列0下標開頭呢?

最簡單的方法就是 if 判斷

if (re a r== elem.length-1){// 走到了隊尾
	rear = 0;
}

這時候如果利用取余運算呢? 會發現有不同的運算效果
假設一邊有插入一邊有洗掉,那么這個時候即可實作回圈操作對立達到堆空間的利用的同時復雜度還是O(1)

佇列長度為8, rear+1取余結果
1%81
2%82
3%83
4%80
5%85
6%88
7%88
8%80
9%8: 不會出現這種情況,rear+1==front的話就已經是滿佇列1

在這里插入圖片描述
_FFFFFF,t_70,g_se,x_16)

2.2.1 陣列實作回圈佇列

這是一個 OJ 鏈接
方案1會浪費一個位置的佇列空間,代碼如下:

class MyCircularQueue {
    private int[] elem;
    private int front, rear;

    public MyCircularQueue(int k) {
        this.elem = new int[k+1];
    }


    /**
     * 入佇列
     *
     * @param value 值
     * @return
     */
    public boolean enQueue(int value) {
        if ((this.rear + 1) % this.elem.length == this.front) {
            return false;//滿了
        } else {
            this.elem[this.rear] = value;
            this.rear = (this.rear + 1) % this.elem.length;
            return true;
        }
    }

    /**
     * 出佇列
     *
     * @return
     */
    public boolean deQueue() {
        if (this.front == this.rear) {
            return false;
        } else {
            int val = this.elem[this.front];
//            this.front = (this.front + 1) % this.elem.length;// 因為是回圈,所以不能直接 front+1
            return true;
        }
    }

    /**
     * 取隊頭元素【相當于 peek 】
     *
     * @return
     */
    public int Front() {
        if (this.front == this.rear) {
            return -1;// leetcode 拋例外會認為是你的代碼錯誤,所以不能拋例外
        } else {
            int val = this.elem[this.front];
            return val;
        }
    }

    /**
     * 取隊尾元素
     * rear處于0位置則回傳this.elem.length-1
     * 所以不能直接進行 -1 操作
     *
     * @return
     */
    public int Rear() {
        if (this.rear == this.front) {
            return -1;
        } else {
            if (this.rear == 0) {
                return this.elem[this.elem.length - 1];
            } else {
                return this.elem[this.rear - 1];
            }
        }
    }

    public boolean isEmpty() {
        return this.front == this.rear;
    }

    public boolean isFull() {
        return this.rear + 1 == this.front;
    }
}

方案2,通過一個額外的變數來記錄佇列的狀態【并非 OJ 題目代碼,只是提供一個思路,把最后的佇列空間利用完】

public class my_Queue_list<E> {
    E[] elem = (E[]) new Object[5];
    // 佇列有效區間[head, tail)
    private int head = 0;
    private int tail = 0;
    private int size = 0;

    // 1.入佇列
    boolean offer(E val) {
        if (size == elem.length) {
            return false;
        } else {
            elem[tail++] = val;
            tail = tail % elem.length;
            ++size;
            return true;
        }
    }

    // 2.出佇列
    E poll() {
        if (size == 0) {
            return null;
        } else {
            E ret = (E) elem[head++];
            head = head % elem.length;
            --size;
            return ret;
        }
    }

    // 3.取隊首元素
    E peek() {
        if (size == 0) {
            return null;
        } else {
            return (E) elem[head];
        }
    }

    // 4.列印
    void display() {
        for (int i = 0; i < size; i++) {
            System.out.print(elem[i] + " ");
        }
    }

    private static void test_offer() {
        my_Queue_list my_queue_list = new my_Queue_list();
        for (int i = 0; i < 5; i++) {
            my_queue_list.offer(Integer.valueOf(i));
        }
        my_queue_list.display();
    }

    private static void test_poll() {
        my_Queue_list my_queue_list = new my_Queue_list();
        for (int i = 0; i < 5; i++) {
            my_queue_list.offer(Integer.valueOf(i));
        }
        for (int i = 0; i < 5; i++) {
            System.out.print(my_queue_list.poll() + " ");
        }
    }

    private static void test_peek() {
        my_Queue_list my_queue_list = new my_Queue_list();
        for (int i = 0; i < 5; i++) {
            my_queue_list.offer(Integer.valueOf(i));
        }
        System.out.println(my_queue_list.peek());
    }

    public static void main(String[] args) {
    	// 放置測驗用例
        test_peek();
    }
}

2.2.2 單鏈表實作Queue

class Node<E>{
    private E val;
    private Node next;
    private int usedSize;

    public Node(E val) {
        this.val = val;
        this.usedSize = 0;
    }
    Node front;
    Node rear;

    /**
     * 入佇列
     * @param val 值
     * @return
     */
    E offer(E val){
        Node node = new Node(val);
        if (this.front == null){
            this.front = node;
            this.rear = node;
        }else{
            this.rear.next = node;
            this.rear = node;
        }
        ++this.usedSize;
        return (E) this.rear.val;
    }

    /**
     * 出佇列
     * @return
     */
    E poll(){
        if (this.front == null){
            throw new NullPointerException("Queue is empty !!!");
        }else{
            E ret = (E) this.front.val;
            if (this.front.next == null){
                this.front = null;
                this.rear = null;
            }else{
                this.front = this.front.next;
            }
            --this.usedSize;
            return ret;
        }
    }

    /**
     * 出對頭元素但不洗掉
     * @return
     */
    E peek(){
        if (this.front == null){
            throw new NullPointerException("Queue is empty !!!");
        }else{
            E ret = (E) this.front.val;
            return ret;
        }
    }

    /**
     * 為空
     * @return
     */
    boolean isEmpty(){
        return this.usedSize == 0;
    }

    /**
     * 佇列長度
     * @return
     */
    int size(){
        return this.usedSize;
    }
}
public class MyQueueLinked {
    private static void tstOffer(){
        Node node = new Node(null);
        for (int i = 0; i < 8; i++) {
            System.out.print(node.offer(i) + " ");
        }
    }

    private static void testPoll(){
        Node node = new Node(null);
        for (int i = 0; i < 8; i++) {
            node.offer(i);
        }
        for (int i = 0; i < 9; i++) {
            System.out.print(node.poll()+" ");
        }
    }

    private static void testPeek(){
        Node node = new Node(null);
        for (int i = 0; i < 8; i++) {
            node.offer(i);
        }
        for (int i = 0; i < 9; i++) {
            System.out.print(node.peek()+" ");
        }
    }
    public static void main(String[] args) {
    	// 放置測驗用例
        testPeek();
    }
}

3. Stack 和 Queue 常用 API 總結

Stack

方法解釋
E push(E item)壓堆疊并回傳壓入的元素
E pop()彈出堆疊頂元素并回傳彈出的元素
E peek()查看頂元素且不彈出,保留在堆疊中
boolean empty()堆疊是否為空

Queue

拋出例外回傳值
入佇列boolean add(e)boolean offer(e)
出佇列E remove()E poll()
隊首元素E element()E peek()

4. 結尾語

兩堆疊共享空間這種操作我還不會,以后會學會了會繼續更新堆疊內容
堆疊和佇列說簡單也簡單,說難也有一絲的難度,
下面是我的感悟:
人生,就像是一個很大的堆疊演變,
自下而上的增長,不僅僅是自然萬物,也是我們的成長經歷程序,
從出生時我們赤裸裸的來到這個世間,漸漸地長大,知道我們變老,經歷的周圍人的生老病死,最終我們還的赤裸裸地衣蕉訓“鄉”,

人生,又放佛是一天一天小小的堆疊重現,
呀呀學語的時候,父母每天為抱著我們不斷的進出家門,青少年的時候有叛逆,青年的時候高中和大學的接軌,是否和父母一樣保持著童年時期的聯系,壯年時候將會奔波于家和事業之間,老年了,我想我會小園香徑獨徘徊于養老院門里屋前,

人生,更需要有堆疊的精神體現,
在哪里跌倒就在哪里爬起,無論是否見到堆疊底,我們始終應該保持堆疊定的仰望天空,只要有希望,不斷進取,出頭之日將會重現,困難不會永遠存在,強者才會勇往直前,

人生,其實就是一個大大的佇列演變,
無知童年,快樂少年,稚嫩青年,成熟中年,安逸晚年,

人生,也是一個又一個小小的佇列重現,
春夏秋冬輪回年年,早中晚夜回圈天天,變化的是時間,不變的是對未來執著的信念,

人生,更需要有佇列精神的體現,
南極到北極,不過時南緯 90 度到北緯 90 度的佇列,如果中途猶豫,臨時轉向,也許只能與企鵝或北極熊相伴,可事實是無論堅持哪個方向,你都會到達終點,

大部分人都是普通人,學習資料結構,我很笨,想著宏偉的計劃,卻發現別人學一遍的我需要兩遍才能弄明白,佇列精神對于普通人來說,已經很寶貴,聰明人可以轉向,繞過許多溝壑以最快的速度到達終點,但是普通人只能腳踏實地的一步一個腳印走完該走的路,

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/305565.html

標籤:java

上一篇:爆肝!!!爬蟲原始碼分享!tkinter界面!記得點贊+收藏哦!

下一篇:??假如面試官讓你聊聊Sentinel(哨兵),看完這篇文章足矣!??

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【C++】Microsoft C++、C 和匯編程式檔案

    ......

    uj5u.com 2020-09-10 00:57:23 more
  • 例外宣告

    相比于斷言適用于排除邏輯上不可能存在的狀態,例外通常是用于邏輯上可能發生的錯誤。 例外宣告 Item 1:當函式不可能拋出例外或不能接受拋出例外時,使用noexcept 理由 如果不打算拋出例外的話,程式就會認為無法處理這種錯誤,并且應當盡早終止,如此可以有效地阻止例外的傳播與擴散。 示例 //不可 ......

    uj5u.com 2020-09-10 00:57:27 more
  • Codeforces 1400E Clear the Multiset(貪心 + 分治)

    鏈接:https://codeforces.com/problemset/problem/1400/E 來源:Codeforces 思路:給你一個陣列,現在你可以進行兩種操作,操作1:將一段沒有 0 的區間進行減一的操作,操作2:將 i 位置上的元素歸零。最終問:將這個陣列的全部元素歸零后操作的最少 ......

    uj5u.com 2020-09-10 00:57:30 more
  • UVA11610 【Reverse Prime】

    本人看到此題沒有翻譯,就附帶了一個自己的翻譯版本 思考 這一題,它的第一個要求是找出所有 $7$ 位反向質數及其質因數的個數。 我們應該需要質數篩篩選1~$10^{7}$的所有數,這里就不慢慢介紹了。但是,重讀題,我們突然發現反向質數都是 $7$ 位,而將它反過來后的數字卻是 $6$ 位數,這就說明 ......

    uj5u.com 2020-09-10 00:57:36 more
  • 統計區間素數數量

    1 #pragma GCC optimize(2) 2 #include <bits/stdc++.h> 3 using namespace std; 4 bool isprime[1000000010]; 5 vector<int> prime; 6 inline int getlist(int ......

    uj5u.com 2020-09-10 00:57:47 more
  • C/C++編程筆記:C++中的 const 變數詳解,教你正確認識const用法

    1、C中的const 1、區域const變數存放在堆疊區中,會分配記憶體(也就是說可以通過地址間接修改變數的值)。測驗代碼如下: 運行結果: 2、全域const變數存放在只讀資料段(不能通過地址修改,會發生寫入錯誤), 默認為外部聯編,可以給其他源檔案使用(需要用extern關鍵字修飾) 運行結果: ......

    uj5u.com 2020-09-10 00:58:04 more
  • 【C++犯錯記錄】VS2019 MFC添加資源不懂如何修改資源宏ID

    1. 首先在資源視圖中,添加資源 2. 點擊新添加的資源,復制自動生成的ID 3. 在解決方案資源管理器中找到Resource.h檔案,編輯,使用整個專案搜索和替換的方式快速替換 宏宣告 4. Ctrl+Shift+F 全域搜索,點擊查找全部,然后逐個替換 5. 為什么使用搜索替換而不使用屬性視窗直 ......

    uj5u.com 2020-09-10 00:59:11 more
  • 【C++犯錯記錄】VS2019 MFC不懂的批量添加資源

    1. 打開資源頭檔案Resource.h,在其中預先定義好宏 ID(不清楚其實ID值應該設定多少,可以先新建一個相同的資源項,再在這個資源的ID值的基礎上遞增即可) 2. 在資源視圖中選中專案資源,按F7編輯資源檔案,按 ID 型別 相對路徑的形式添加 資源。(別忘了先把檔案拷貝到專案中的res檔案 ......

    uj5u.com 2020-09-10 01:00:19 more
  • C/C++編程筆記:關于C++的參考型別,專供新手入門使用

    今天要講的是C++中我最喜歡的一個用法——參考,也叫別名。 參考就是給一個變數名取一個變數名,方便我們間接地使用這個變數。我們可以給一個變數創建N個參考,這N + 1個變數共享了同一塊記憶體區域。(參考型別的變數會占用記憶體空間,占用的記憶體空間的大小和指標型別的大小是相同的。雖然參考是一個物件的別名,但 ......

    uj5u.com 2020-09-10 01:00:22 more
  • 【C/C++編程筆記】從頭開始學習C ++:初學者完整指南

    眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......

    uj5u.com 2020-09-10 01:00:41 more
最新发布
  • Rust中的智能指標:Box<T> Rc<T> Arc<T> Cell<T> RefCell<T> Weak

    Rust中的智能指標是什么 智能指標(smart pointers)是一類資料結構,是擁有資料所有權和額外功能的指標。是指標的進一步發展 指標(pointer)是一個包含記憶體地址的變數的通用概念。這個地址參考,或 ” 指向”(points at)一些其 他資料 。參考以 & 符號為標志并借用了他們所 ......

    uj5u.com 2023-04-20 07:24:10 more
  • Java的值傳遞和參考傳遞

    值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......

    uj5u.com 2023-04-20 07:24:04 more
  • [2]SpinalHDL教程——Scala簡單入門

    第一個 Scala 程式 shell里面輸入 $ scala scala> 1 + 1 res0: Int = 2 scala> println("Hello World!") Hello World! 檔案形式 object HelloWorld { /* 這是我的第一個 Scala 程式 * 以 ......

    uj5u.com 2023-04-20 07:23:58 more
  • 理解函式指標和回呼函式

    理解 函式指標 指向函式的指標。比如: 理解函式指標的偽代碼 void (*p)(int type, char *data); // 定義一個函式指標p void func(int type, char *data); // 宣告一個函式func p = func; // 將指標p指向函式func ......

    uj5u.com 2023-04-20 07:23:52 more
  • Django筆記二十五之資料庫函式之日期函式

    本文首發于公眾號:Hunter后端 原文鏈接:Django筆記二十五之資料庫函式之日期函式 日期函式主要介紹兩個大類,Extract() 和 Trunc() Extract() 函式作用是提取日期,比如我們可以提取一個日期欄位的年份,月份,日等資料 Trunc() 的作用則是截取,比如 2022-0 ......

    uj5u.com 2023-04-20 07:23:45 more
  • 一天吃透JVM面試八股文

    什么是JVM? JVM,全稱Java Virtual Machine(Java虛擬機),是通過在實際的計算機上仿真模擬各種計算機功能來實作的。由一套位元組碼指令集、一組暫存器、一個堆疊、一個垃圾回收堆和一個存盤方法域等組成。JVM屏蔽了與作業系統平臺相關的資訊,使得Java程式只需要生成在Java虛擬機 ......

    uj5u.com 2023-04-20 07:23:31 more
  • 使用Java接入小程式訂閱訊息!

    更新完微信服務號的模板訊息之后,我又趕緊把微信小程式的訂閱訊息給實作了!之前我一直以為微信小程式也是要企業才能申請,沒想到小程式個人就能申請。 訊息推送平臺🔥推送下發【郵件】【短信】【微信服務號】【微信小程式】【企業微信】【釘釘】等訊息型別。 https://gitee.com/zhongfuch ......

    uj5u.com 2023-04-20 07:22:59 more
  • java -- 緩沖流、轉換流、序列化流

    緩沖流 緩沖流, 也叫高效流, 按照資料型別分類: 位元組緩沖流:BufferedInputStream,BufferedOutputStream 字符緩沖流:BufferedReader,BufferedWriter 緩沖流的基本原理,是在創建流物件時,會創建一個內置的默認大小的緩沖區陣列,通過緩沖 ......

    uj5u.com 2023-04-20 07:22:49 more
  • Java-SpringBoot-Range請求頭設定實作視頻分段傳輸

    老實說,人太懶了,現在基本都不喜歡寫筆記了,但是網上有關Range請求頭的文章都太水了 下面是抄的一段StackOverflow的代碼...自己大修改過的,寫的注釋挺全的,應該直接看得懂,就不解釋了 寫的不好...只是希望能給視頻網站開發的新手一點點幫助吧. 業務場景:視頻分段傳輸、視頻多段傳輸(理 ......

    uj5u.com 2023-04-20 07:22:42 more
  • Windows 10開發教程_編程入門自學教程_菜鳥教程-免費教程分享

    教程簡介 Windows 10開發入門教程 - 從簡單的步驟了解Windows 10開發,從基本到高級概念,包括簡介,UWP,第一個應用程式,商店,XAML控制元件,資料系結,XAML性能,自適應設計,自適應UI,自適應代碼,檔案管理,SQLite資料庫,應用程式到應用程式通信,應用程式本地化,應用程式 ......

    uj5u.com 2023-04-20 07:22:35 more