【C++初學】課后作業匯總復習(七) 指針-深淺copy

1、 HugeInt類:構造、+、cout

Description:
32位整數的計算機可以表示整數的范圍近似為-20億到+20億。在這個范圍內操作一般不會出現問題,但是有的應用程序可能需要使用超出上述范圍的整數。C++可以滿足這個需求,創建功能強大的新的數據類型。

定義一個HugeInt類,使用一個數組存儲大整數的每一位。如 short integer[ 40 ]; 即可實現存儲位數為40位的整數。暫不考慮負數。請根據主函數為該類:

1)定義兩個構造,分別接受int和string類型的參數;當參數為string類型時,可以使用字符串處理函數將string類型轉換為數值類型。

2)重載+運算,分別能夠實現兩個HugeInt對象相加,HugeInt與int相加,HugeInt與string相加。提示,先實現兩個HugeInt相加,當HugeInt與int相加時,可以將int通過轉換構造函數轉換為HugeInt類型,然后調用兩個HugeInt相加。HugeInt與string相加亦如此。

3)重載<<運算符。

注意:程序前綴、后綴代碼已給出。

Sample Input:

Sample Output:
在這里插入圖片描述

//StudybarCommentBegin
#include <iostream>
#include <cctype> // isdigit function prototype
#include <cstring> // strlen function prototype
using namespace std;class HugeInt
{friend ostream &operator<<( ostream &, const HugeInt & );
public:static const int digits = 30;HugeInt( long = 0 ); // conversion/default constructorHugeInt( const char * ); // conversion constructor// addition operator; HugeInt + HugeIntHugeInt operator+( const HugeInt & ) const;// addition operator; HugeInt + intHugeInt operator+( int ) const;// addition operator;// HugeInt + string that represents large integer valueHugeInt operator+( const char * ) const;int getLength() const;
private:short integer[ digits ];
}; // end class HugeInt//StudybarCommentEnd// Implementation of HugeInt class
HugeInt::HugeInt(long value) {// Initialize all digits to 0for (int i = 0; i < digits; i++) {integer[i] = 0;}// Store digits in reverse orderfor (int i = digits - 1; value != 0 && i >= 0; i--) {integer[i] = value % 10;value /= 10;}
}HugeInt::HugeInt(const char *str) {// Initialize all digits to 0for (int i = 0; i < digits; i++) {integer[i] = 0;}int len = strlen(str);int j = digits - 1;// Store digits in reverse orderfor (int i = len - 1; i >= 0 && j >= 0; i--) {if (isdigit(str[i])) {integer[j--] = str[i] - '0';}}
}HugeInt HugeInt::operator+(const HugeInt &op2) const {HugeInt temp;int carry = 0;for (int i = digits - 1; i >= 0; i--) {temp.integer[i] = integer[i] + op2.integer[i] + carry;if (temp.integer[i] > 9) {temp.integer[i] %= 10;carry = 1;} else {carry = 0;}}return temp;
}HugeInt HugeInt::operator+(int op2) const {return *this + HugeInt(op2);
}HugeInt HugeInt::operator+(const char *op2) const {return *this + HugeInt(op2);
}int HugeInt::getLength() const {int i;for (i = 0; (i < digits) && (integer[i] == 0); i++); // skip leading zerosreturn (i == digits) ? 1 : (digits - i);
}ostream &operator<<(ostream &output, const HugeInt &num) {int i;for (i = 0; (i < HugeInt::digits) && (num.integer[i] == 0); i++); // skip leading zerosif (i == HugeInt::digits) {output << 0;} else {for (; i < HugeInt::digits; i++) {output << num.integer[i];}}return output;
}//StudybarCommentBegin
int main()
{HugeInt n1( 7654321 );HugeInt n2( 7891234 );HugeInt n3( "99999999999999999999999999999" );HugeInt n4( "1" );HugeInt result;cout << "n1 is " << n1 << "\nn2 is " << n2<< "\nn3 is " << n3 << "\nn4 is " << n4<< "\nresult is " << result << "\n\n";result = n1 + n2;cout << n1 << " + " << n2 << " = " << result << "\n\n";cout << n3 << " + " << n4 << "\n= " << ( n3 + n4 ) << "\n\n";result = n1 + 9;cout << n1 << " + " << 9 << " = " << result << endl;result = n2 + "10000";cout << n2 << " + " << "10000" << " = " << result << endl;return 0;
} // end main//StudybarCommentEnd

2、對象指針定義形式——代碼糾正

對象指針定義形式

類名 *對象指針名;

例:

Point a(5,10);

Piont *ptr;

ptr=&a;

通過指針訪問對象成員

對象指針名->成員名

例:ptr->getx() 相當于 (*ptr).getx();

例6-12使用指針來訪問Point類的成員

//6_12.cpp

#include

using namespace std;

class Point {

public:

Point(int x = 0, int y = 0) : x(x), y(y) { }

int getX() const { return this->x; }

int getY() const { return y; }

private:

int x, y;

};

int main() {

Point a(4, 5);

Point p1 = &a; //定義對象指針,用a的地址初始化

cout << p1.getX() << endl;//用指針訪問對象成員

cout << a->getY() << endl; //用對象名訪問對象成員

return 0;

}

本題輸出結果

4
5

#include <iostream>
using namespace std;class Point {
public:Point(int x = 0, int y = 0) : x(x), y(y) { }int getX() const { return this->x; }int getY() const { return y; }
private:int x, y;
};int main() {Point a(4, 5);Point *p1 = &a; // 定義對象指針,用a的地址初始化cout << p1->getX() << endl; // 用指針訪問對象成員cout << a.getY() << endl; // 用對象名訪問對象成員return 0;
}

3、動態創建對象舉例

動態內存分配

動態申請內存操作符 new

new 類型名T(初始化參數列表)

功能:在程序執行期間,申請用于存放T類型對象的內存空間,并依初值列表賦以初值。

結果值:成功:T類型的指針,指向新分配的內存;失敗:拋出異常。

釋放內存操作符delete

delete 指針p

功能:釋放指針p所指向的內存。p必須是new操作的返回值。

本題給出了前綴,本題程序,應該和下列代碼等價!

例6-16 動態創建對象舉例

#include

using namespace std;

class Point {

public:

Point() : x(0), y(0) {

cout<<“Default Constructor called.”<<endl;

}

Point(int x, int y) : x(x), y(y) {

cout<< “Constructor called.”<<endl;

}

~Point() { cout<<“Destructor called.”<<endl; }

int getX() const { return x; }

int getY() const { return y; }

void move(int newX, int newY) {

x = newX;

y = newY;

}

private:

int x, y;

};

int main() {
cout << "Step one: " << endl;
Point *ptr1 = new Point; //調用默認構造函數
cout<getX()<<endl; //輸出GetX
delete ptr1; //刪除對象,自動調用析構函數
cout << "Step two: " << endl;
ptr1 = new Point(1,2);
cout<getX()<<endl; //輸出GetX
delete ptr1;
return 0;
}

//StudybarCommentBegin
#include <iostream>
using namespace std;
class Point {
public:Point();Point(int x, int y);~Point();int getX() const; int getY() const; void move(int newX, int newY);
private:int x, y;
};
//StudybarCommentEndPoint::Point() : x(0), y(0) {cout << "Default Constructor called." << endl;
}Point::Point(int x, int y) : x(x), y(y) {cout << "Constructor called." << endl;
}Point::~Point() {cout << "Destructor called." << endl;
}int Point::getX() const {return x;
}int Point::getY() const {return y;
}void Point::move(int newX, int newY) {x = newX;y = newY;
}int main() {cout << "Step one: " << endl;Point *ptr1 = new Point; //調用默認構造函數cout << ptr1->getX() << endl; //輸出GetXdelete ptr1; //刪除對象,自動調用析構函數cout << "Step two: " << endl;ptr1 = new Point(1,2);cout << ptr1->getX() << endl; //輸出GetXdelete ptr1;return 0;
}

4、 動態創建對象數組舉例

例6-17 動態創建對象數組舉例

分配和釋放動態數組

分配:new 類型名T [ 數組長度 ]

數組長度可以是任何表達式,在運行時計算

釋放:delete[] 數組名p

釋放指針p所指向的數組。
p必須是用new分配得到的數組首地址。

例6-17 動態創建對象數組舉例

#include<iostream>using namespace std;#include <iostream>using namespace std;class Point {public:Point() : x(0), y(0) {cout<<"Default Constructor called."<<endl;}Point(int x, int y) : x(x), y(y) {cout<< "Constructor called."<<endl;}~Point() { cout<<"Destructor called."<<endl; }int getX() const { return x; }int getY() const { return y; }void move(int newX, int newY) {x = newX;y = newY;}private:int x, y;};int main() {
Point *ptr = new Point[2]; //創建對象數組
ptr[0].move(5, 10); //通過指針訪問數組元素的成員
cout<<ptr[0].getY()<<endl;
ptr[1].move(15, 20); //通過指針訪問數組元素的成員
cout<<ptr[1].getY()<<endl;   
cout << "Deleting..." << endl;
delete[] ptr; //刪除整個對象數組
return 0;
}

5、淺層復制與深層復制

淺層復制

實現對象間數據元素的一一對應復制。

深層復制

當被復制的對象數據成員是指針類型時,不是復制該指針成員本身,而是將指針所指對象進行復制

例6-21 對象的淺層復制

#include

#include

using namespace std;

class Point {

//類的聲明同例6-16

//……

};

class ArrayOfPoints {

//類的聲明同例6-18

//……

};

int main() {

int count;

cout << "Please enter the count of points: ";

cin >> count;

ArrayOfPoints pointsArray1(count); //創建對象數組

pointsArray1.element(0).move(5,10);

pointsArray1.element(1).move(15,20);

ArrayOfPoints pointsArray2(pointsArray1); //創建副本

cout << “Copy of pointsArray1:” << endl;

cout << "Point_0 of array2: " << pointsArray2.element(0).getX() << ", "

<< pointsArray2.element(0).getY() << endl;

cout << "Point_1 of array2: " << pointsArray2.element(1).getX() << ", "

<< pointsArray2.element(1).getY() << endl;

pointsArray1.element(0).move(25, 30);

pointsArray1.element(1).move(35, 40);

cout<<“After the moving of pointsArray1:”<<endl;

cout << "Point_0 of array2: " << pointsArray2.element(0).getX() << ", "

<< pointsArray2.element(0).getY() << endl;

cout << "Point_1 of array2: " << pointsArray2.element(1).getX() << ", "

<< pointsArray2.element(1).getY() << endl;

return 0;

}

運行結果如下:

Please enter the number of points:2

Default Constructor called.

Default Constructor called.

Copy of pointsArray1:

Point_0 of array2: 5, 10

Point_1 of array2: 15, 20

After the moving of pointsArray1:

Point_0 of array2: 25, 30

Point_1 of array2: 35, 40

Deleting…

Destructor called.

Destructor called.

Deleting…

接下來程序出現運行錯誤。

在這里插入圖片描述
例6-22 對象的深層復制

#include

#include

using namespace std;

class Point { //類的聲明同例6-16

};

class ArrayOfPoints {

public:

ArrayOfPoints(const ArrayOfPoints& pointsArray);

//其他成員同例6-18

};

ArrayOfPoints::ArrayOfPoints(const ArrayOfPoints& v) {

size = v.size;

points = new Point[size];

for (int i = 0; i < size; i++)

points[i] = v.points[i];

}

int main() {

//同例6-20

}

程序的運行結果如下:

Please enter the number of points:2

Default Constructor called.

Default Constructor called.

Default Constructor called.

Default Constructor called.

Copy of pointsArray1:

Point_0 of array2: 5, 10

Point_1 of array2: 15, 20

After the moving of pointsArray1:

Point_0 of array2: 5, 10

Point_1 of array2: 15, 20

Deleting…

Destructor called.

Destructor called.

Deleting…

Destructor called.

Destructor called.

在這里插入圖片描述

#include <iostream>
#include <cassert>
using namespace std;class Point {
public:Point() : x(0), y(0) {cout << "Default Constructor called." << endl;}~Point() {cout << "Destructor called." << endl;}void move(int newX, int newY) { x = newX; y = newY; }int getX() const { return x; }int getY() const { return y; }
private:int x, y;
};class ArrayOfPoints {
public:ArrayOfPoints(int size) : size(size) {points = new Point[size];}// 復制構造函數(深層復制)ArrayOfPoints(const ArrayOfPoints& v) {size = v.size;points = new Point[size];for (int i = 0; i < size; i++)points[i] = v.points[i];}~ArrayOfPoints() {cout << "Deleting..." << endl;delete[] points;}Point& element(int index) {assert(index >= 0 && index < size);return points[index];}private:Point* points;int size;
};int main() {int count;cout << "Please enter the number of points:" << endl;cin >> count;ArrayOfPoints pointsArray1(count); //創建對象數組pointsArray1.element(0).move(5, 10);pointsArray1.element(1).move(15, 20);ArrayOfPoints pointsArray2(pointsArray1); //創建副本(深層復制)cout << "Copy of pointsArray1:" << endl;cout << "Point_0 of array2: " << pointsArray2.element(0).getX() << ", " << pointsArray2.element(0).getY() << endl;cout << "Point_1 of array2: " << pointsArray2.element(1).getX() << ", " << pointsArray2.element(1).getY() << endl;pointsArray1.element(0).move(25, 30);pointsArray1.element(1).move(35, 40);cout << "After the moving of pointsArray1:" << endl;cout << "Point_0 of array2: " << pointsArray2.element(0).getX() << ", " << pointsArray2.element(0).getY() << endl;cout << "Point_1 of array2: " << pointsArray2.element(1).getX() << ", " << pointsArray2.element(1).getY() << endl;return 0;
}

6、動態數組——基本模板類

本題目有后綴

題目描述:

動態數組,是相對于靜態數組而言。靜態數組的長度是編程時程序員預先定義好的,在整個程序運行中,數組大小無法改變。

而動態數組則不然,它可以隨程序運行的需要而在運行時重新指定大小。

動態數組的內存空間是從堆(heap)上分配(即動態分配)的。是通過執行new(或malloc等函數)操作,而為其分配存儲空間。當程序執行到這些語句時,才為其分配。

對于動態數組類所申請的內存,在使用完必須由程序員自己釋放,否則嚴重會引起內存泄露。

所以內存的申請一定要有借有還,才能再借不難,也要注意,不能多還。

已知動態數組模板類的定義如下。

請補充完整

1、構造函數

2、析構函數

3、返回空間大小的 capacity() 函數

4、operator[] 重載

template
class DynamicArray {
private:
T* array; //pointer ,一個T類型的指針
unsigned int mallocSize; //分配空間的大小。

public:
//Constructors
// cout<<endl<< “new T[”<mallocSize<<“] malloc “<< this->mallocSize << “*”<<sizeof(T)<<”=”<mallocSize *sizeof(T)<<" bytes memory in heap";
DynamicArray(unsigned length, const T &content) ; // mallocSize=length; 設置每個元素的初始內容是 content;

// Destructors
// cout<<endl<< “delete[] array free “<< this->mallocSize << “*”<<sizeof(T)<<”=”<mallocSize *sizeof(T)<<" bytes memory in heap";
~DynamicArray();

//return the this->mallocSize
unsigned int capacity() const;

// for the array[i]=someT.
T& operator[](unsigned int i) ;
};

輸入一個整數

輸出請分析參見下面的用例和程序后綴。

樣例輸入:

3

樣例輸出

new T[3] malloc 34=12 bytes memory in heap
new T[3] malloc 3
8=24 bytes memory in heap
capacity:3
-1 -1 -1
-2.1 -2.1 -2.1
0 1 2
0 1.1 2.2
delete[] array free 38=24 bytes memory in heap
delete[] array free 3
4=12 bytes memory in heap

#include <iostream>
using namespace std;template <typename T>
class DynamicArray {
private:T* array; //pointer  ,一個T類型的指針unsigned int mallocSize; //分配空間的大小。public://Constructors // cout<<endl<< "new T["<<this->mallocSize<<"] malloc "<< this->mallocSize << "*"<<sizeof(T)<<"="<<this->mallocSize *sizeof(T)<<" bytes memory in heap";DynamicArray(unsigned length, const T &content) {mallocSize = length;array = new T[length];for (unsigned int i = 0; i < length; ++i) {array[i] = content;}cout << "new T[" << mallocSize << "] malloc " << mallocSize << "*" << sizeof(T) << "=" << mallocSize * sizeof(T) << " bytes memory in heap\n";}// Destructors// cout<<endl<< "delete[] array free "<< this->mallocSize << "*"<<sizeof(T)<<"="<<this->mallocSize *sizeof(T)<<" bytes memory in heap";~DynamicArray() {cout << endl << "delete[] array free " << mallocSize << "*" << sizeof(T) << "=" << mallocSize * sizeof(T) << " bytes memory in heap";delete[] array;}//return the this->mallocSizeunsigned int capacity() const {return mallocSize;}// for the array[i]=someT.T& operator[](unsigned int i) {return array[i];}
};

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

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

相關文章

【C++】 —— 筆試刷題day_16

刷題_day16&#xff0c;繼續加油啊 一、字符串替換 題目解析 這道題是一道簡單的字符題目&#xff0c;題目給我們一個字符串A&#xff0c;和n表示A字符串的長度&#xff0c;再給出一個字符數組arg&#xff0c;m表示arg中是數據個數。 然我們在字符串A中找到%s然后替換成arg中的…

n8n 本地部署及實踐應用,實現零成本自動化運營 Telegram 頻道(保證好使)

n8n 本地部署及實踐應用&#xff0c;實現零成本自動化運營 Telegram 頻道&#xff08;保證好使&#xff09; 簡介 n8n 介紹 一、高度可定制性 二、豐富的連接器生態 三、自托管部署&#xff08;本地部署&#xff09; 四、社區驅動 n8n 的部署 一、前期準備 二、部署步…

flutter 桌面應用之系統托盤

系統托盤(Tray) 系統托盤就是狀態欄里面對應的圖標點擊菜單 主要有兩款框架 框架一句話評價tray_manager輕量、簡單、易用&#xff0c;適合常規托盤功能system_tray更底層、更強大、支持圖標/菜單/消息彈窗等更多功能&#xff0c;但復雜度更高 &#x1f9f1; 基礎能力對比 …

修改idea/android studio等編輯器快捷注釋從當前行開頭的反人類行為

不知道什么時候開始&#xff0c;idea編輯的快捷注釋開始從當前行開頭出現了&#xff0c;顯得實在是難受&#xff0c;我只想讓在當前行代碼的部份開始縮進兩個字符開始&#xff0c;這樣才會顯得更舒服。不知道有沒有強迫癥的猴子和我一樣&#xff0c;就像下面的效果&#xff1a;…

MySQL慢查詢全攻略:定位、分析與優化實戰

&#x1f680; MySQL慢查詢全攻略&#xff1a;定位、分析與優化實戰 #數據庫優化 #性能調優 #SQL優化 #MySQL實戰 一、慢查詢定位&#xff1a;找到性能瓶頸 1.1 開啟慢查詢日志 -- 查看當前配置 SHOW VARIABLES LIKE %slow_query%; -- 動態開啟&#xff08;重啟失效&…

當原型圖與文字說明完全不同時,測試要怎么做?

當測試遇上左右手互搏的需求&#xff0c;怎么辦&#xff1f; "這個彈窗樣式怎么和文檔寫的不一樣&#xff1f;"、"按鈕位置怎么跑到左邊去了&#xff1f;"——根據Deloitte的調查&#xff0c;62%的項目存在原型圖與需求文檔不一致的情況。這種"精神分…

關于量化交易在拉盤砸盤方面應用的部分思考

關于“砸盤”的深層解析與操盤邏輯 ??一、砸盤的本質與市場含義?? ??砸盤??指通過集中拋售大量籌碼導致價格快速下跌的行為&#xff0c;其核心目標是??制造恐慌、清洗浮籌或實現利益再分配??。不同場景下的砸盤含義不同&#xff1a; ??主動砸盤&#xff08;操控…

【項目管理】第12章 項目質量管理-- 知識點整理

項目管理-相關文檔,希望互相學習,共同進步 風123456789~-CSDN博客 (一)知識總覽 項目管理知識域 知識點: (項目管理概論、立項管理、十大知識域、配置與變更管理、績效域) 對應:第6章-第19章 第6章 項目管理概論 4分第13章 項目資源管理 3-4分第7章 項目…

一個好看的圖集展示html頁面源碼

源碼介紹 一個好看的圖集展示html頁面源碼&#xff0c;適合展示自己的作品&#xff0c;頁面美觀大氣&#xff0c;也可以作為產品展示或者個人引導頁等等 源碼由HTMLCSSJS組成&#xff0c;記事本打開源碼文件可以進行內容文字之類的修改&#xff0c; 雙擊html文件可以本地運行…

2021第十二屆藍橋杯大賽軟件賽省賽C/C++ 大學 B 組

記錄刷題的過程、感悟、題解。 希望能幫到&#xff0c;那些與我一同前行的&#xff0c;來自遠方的朋友&#x1f609; 大綱&#xff1a; 1、空間-&#xff08;題解&#xff09;-字節單位轉換 2、卡片-&#xff08;題解&#xff09;-可以不用當組合來寫&#xff0c;思維題 3、直…

LabVIEW 中 JSON 數據與簇的轉換

在 LabVIEW 編程中&#xff0c;數據格式的處理與轉換是極為關鍵的環節。其中&#xff0c;將數據在 JSON 格式與 LabVIEW 的簇結構之間進行轉換是一項常見且重要的操作。這里展示的程序片段就涉及到這一關鍵功能&#xff0c;以下將詳細介紹。 一、JSON 數據與簇的轉換功能 &am…

藍橋杯大模板

init.c void System_Init() {P0 0x00; //關閉蜂鳴器和繼電器P2 P2 & 0x1f | 0xa0;P2 & 0x1f;P0 0x00; //關閉LEDP2 P2 & 0x1f | 0x80;P2 & 0x1f; } led.c #include <LED.H>idata unsigned char temp_1 0x00; idata unsigned char temp_old…

通過HTTP協議實現Git免密操作的解決方案

工作中會遇到這樣的問題的。 通過HTTP協議實現Git免密操作的解決方案 方法一&#xff1a;啟用全局憑據存儲&#xff08;推薦&#xff09; 配置憑證存儲? 執行以下命令&#xff0c;讓Git永久保存賬號密碼&#xff08;首次操作后生效&#xff09;&#xff1a; git config --g…

Java常見面試問題

一.Liunx 二.Java基礎 1.final 2.static 3.與equals 三.Collection 1.LIst 2.Map 3.Stream 四、多線程 1.實現方法 2.線程池核心參數 3.應用場景 五、JVM 1.堆 2.棧 六、Spring 1.面向對象 2.IOC 3.AOP 七、Springboot 1.自動裝配 八、SpringCloud 1.Nacos 2.seata 3.ga…

【藍橋杯】第十六屆藍橋杯 JAVA B組記錄

試題 A: 逃離高塔 很簡單&#xff0c;簽到題&#xff0c;但是需要注意精度&#xff0c;用int會有溢出風險 答案&#xff1a;202 package lanqiao.t1;import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWrit…

PyTorch Tensor維度變換實戰:view/squeeze/expand/repeat全解析

本文從圖像數據處理、模型輸入適配等實際場景出發&#xff0c;系統講解PyTorch中view、squeeze、expand和repeat四大維度變換方法。通過代碼演示對比不同方法的適用性&#xff0c;助您掌握數據維度調整的核心技巧。 一、基礎維度操作方法 1. view&#xff1a;內存連續的形狀重…

Kubernetes nodeName Manual Scheduling practice (K8S節點名稱綁定以及手工調度)

Manual Scheduling 在 Kubernetes 中&#xff0c;手動調度框架允許您將 Pod 分配到特定節點&#xff0c;而無需依賴默認調度器。這對于測試、調試或處理特定工作負載非常有用。您可以通過在 Pod 的規范中設置 nodeName 字段來實現手動調度。以下是一個示例&#xff1a; apiVe…

即時編譯器(JIT)的編譯過程是什么?

1. 觸發編譯 JIT編譯的觸發基于熱點代碼檢測&#xff0c;主要通過兩種計數器&#xff1a; ? 方法調用計數器&#xff1a;統計方法被調用的次數&#xff08;默認閾值&#xff1a;C1為1,500次&#xff0c;C2為10,000次&#xff09;。 ? 回邊計數器&#xff1a;統計循環體的執行…

Java基礎:集合List、Map、Set(超詳細版)

集合體系概述 Collection常用方法 補充&#xff1a;addAll() Collection的遍歷方式 迭代器 增強for&#xff08;空集合可以&#xff0c;null不可以&#xff09; lambda 集合對象存儲對象原理 遍歷方式的區別 List集合 特點、特有方法 遍歷方式 &#xff08;同上&#xff09…

Elasticsearch 全面解析

Elasticsearch 全面解析 前言一、簡介核心特性應用場景 二、核心原理與架構設計1. 倒排索引&#xff08;Inverted Index&#xff09;2. 分片與副本機制&#xff08;Sharding & Replication&#xff09;3. 節點角色與集群管理 三、核心特點1. 靈活的查詢語言&#xff08;Que…