【listlist模擬】

list&list模擬

  • 1.list使用
  • 2、list模擬
  • 附錄

1.list使用

?list常見接口不做介紹,跟前面vector有相似之處,跟數據結構list基本一樣。
alt
?因為list使用帶頭的雙向循環鏈表實現的,不能用小標訪問,只能用迭代器或范圍for訪問
alt

?list有成員函數sort,來實現排序
alt
?void unique(),去重,去重先先要排序

void test_list1()
{list<int> lt1 = { 10,2,3,3,4,5,6 };list<int> ::iterator it = lt1.begin();while (it != lt1.end()){cout << *it << " ";it++;}cout << endl;//list不支持sort//sort(lt1.begin(), lt1.end(), greater<int>());//list有自己的排序算法lt1.sort();it = lt1.begin();while (it != lt1.end()){cout << *it << " ";it++;}cout << endl;lt1.sort(greater<int>());it = lt1.begin();while (it != lt1.end()){cout << *it << " ";it++;}cout << endl;//unique 去重//先排序,在去重lt1.unique();for (auto e : lt1){cout << e << " ";  //10 6 5 4 3 2}cout << endl;
}

alt
?splice粘接
?void splice(const _iterator position,list& x);把x粘接到pos位置。

void test_list2()
{//splice:粘接std::list<int> mylist1, mylist2;std::list<int>::iterator it;// set some initial values:for (int i = 1; i <= 4; ++i)mylist1.push_back(i);      // mylist1: 1 2 3 4for (int i = 1; i <= 3; ++i)mylist2.push_back(i * 10);   // mylist2: 10 20 30it = mylist1.begin();++it;                         // points to 2mylist1.splice(it, mylist2); // mylist1: 1 10 20 30 2 3 4// mylist2 (empty)// "it" still points to 2 (the 5th element
}

void splice(const_iterator position,list& x,const_itrator i);
把list的第i個位置的數粘接到position位置.

void test_list3()
{list<int> mylist;for (int i = 1; i <= 4; i++){mylist.push_back(i);  //mylist:   1 2 3 4} //想把3轉移到頭list<int>::iterator  it = find(mylist.begin(), mylist.end(), 3);//void splice (const_iterator position, list& x, const_iterator i);//把list的第i個位置的數粘接到position位置mylist.splice(mylist.begin(), mylist, it);
}

2、list模擬

?先寫申請一個節點的類,把節點弄成一個類,相當與搞了一個新的數據類型。

//這是第一個類 ListNode
//所謂的類就是把成員對象和成員函數封裝在一起.
//這個全部弄成共有
//供后面存儲數據來用
template<class T>
struct ListNode
{ListNode<T>* _next;ListNode<T>* _prev;T _data;//const T& data是接受常量//不能權限放大,會報錯ListNode(const T& data = T()):_next(nullptr),_prev(nullptr),_data(data){}
};

?先寫list的大框架

template<class T>
class list
{typedef ListNode<T> Node;
public://無參構造函數就是默認構造list(){_head = new Node;_head->_prev = _head;_head->_next = _head;}void push_back(const T& data){//...}
private:Node* _head;
};

?寫push_back()先跑通框架

void push_back(const T& data)
{Node* newnode = new Node(data);Node* tail = _head->_prev;//tail newnode  _headtail->_next = newnode;newnode->_prev = tail;newnode->_next = _head;_head->_prev = newnode;
}

alt
?帶頭雙向循環鏈表,非常簡單,寫尾插即可,通過_head->_prev找到尾巴,尾巴,新節點,頭插入即可。


?然后把節點封裝成迭代器。把節點寫成一個類,封裝成迭代器所具有的屬性,即可。先寫·迭代器的行為,在進行封裝。

void list_test1()
{list<int> lt1;lt1.push_back(1);lt1.push_back(2);lt1.push_back(3);lt1.push_back(4);list<int>::iterator it = lt1.begin();while (it != lt1.end()){cout << (*it) << " ";++it;}
}

?通過iterator it = it1.begin(),定義一個對象it,把it初始化為第一個節點的位置,然后進行以下運算符重載,!=,前置++,*就可以了。
?

template<class T>
class ListIterator
{typedef ListIterator<T> Self;typedef ListNode<T> Node;
public:ListIterator(Node* node = T()){_node = node;}//拷貝構造不要//賦值也不要T& operator*(){return _node->_data;}bool operator!=(const Self& it){return _node != it._node;}Self& operator++(){_node = _node->_next;return *this;}
public:Node* _node;
};

?const_iterator可以通過*的運算符重載的返回值+const實現,具體在增加一個模版參數即可,不過多敘述

//Ref引用
//Ptr指針
template<class T,class Ref,class Ptr>
struct  ListIterator
{typedef ListNode<T> Node;typedef ListIterator<T,Ref,Ptr> Self;public:Node* _node;ListIterator(Node* node):_node(node){}//拷貝構造和賦值寫也可以,不寫也可以//這兒是淺拷貝ListIterator(const Self& it){_node = it._node;}//++itSelf& operator++(){_node = _node->_next;return *this;}Self& operator++(int){Self tmp(*this);_node = _node->_next;return tmp;}Self& operator--(){_node = _node->_prev;return *this;}Self& operator--(int){Self tmp(*this);_node = _node->_prev;return tmp;}//T* operator->()//{//	return &(_node->_data);//}Ptr operator->(){return &(_node->_data);}////這個是前置//T& operator*()//{//	return _node->_data;//}//這個是前置Ref operator*(){return _node->_data;}bool operator!=(const Self& it){return _node != it._node;}bool operator==(const Self& it){return _node == it._node;}
};

?寫insert,iterator insert(iterator pos,const T& x);
在pos前面插入,返回的是x所在節點的位置

//在pos前面插入
//沒有迭代器失效
iterator insert(iterator pos, const T& x)
{Node* next = pos._node;Node* newnode = new Node(x);Node* prev = next->_prev;prev->_next = newnode;newnode->_prev = prev;newnode->_next = next;next->_prev = newnode;return iterator(newnode);
}

?寫erase,iterator erase(iterator pos),防止迭代器失效,返回的是pos的下一個位置

//erase后pos失效了,pos指向節點被釋放了
iterator erase(iterator pos)
{assert(pos != end());Node* cur = pos._node;Node* next = cur->_next;Node* prev = cur->_prev;prev->_next = next;next->_prev = prev;delete cur;return iterator(next);
}

?寫void clear(),清空,只剩頭結點

void clear()
{list<T>::iterator it = begin();while (it != end()){//防止迭代器失效it = erase(it);}
}

?寫~list(),先clear,在釋放頭節點

~list()
{//Node* cur = _head->_next;//while (cur != _head)//{//	Node* next = cur->_next;//	delete cur;//	cur = next;//}//delete _head;//_head = nullptr;clear();delete _head;_head = nullptr;
}

?寫voId init_empty()保證有頭結點,在后面插入數據

void empty_init()
{_head = new Node;_head->_next = _head;_head->_prev = _head;
}

?寫拷貝構造,initializer_list< T >為參數的構造函數

//拷貝構造
//lt2(lt1)
list(const list<T>& lt)
{//引入這個是弄個頭結點empty_init();for (const auto& e : lt){push_back(e);}
}list(initializer_list<T>il)
{empty_init();for (const auto& e : il){push_back(e);}
}
//lt1 = lt3
//lt所在的
list<T>& operator= (list<T>lt)
{std :: swap(_head,lt._head);return *this;
}

?再說一下list& operator= (listlt),注意形參是拷貝構造的一份,和賦值_head,把頭地址交換即可,lt在棧楨銷毀時,就會銷毀交換的那個_head.

附錄

#define  _CRT_SECURE_NO_WARNINGS 1
#pragma once
#include <iostream>
#include <list>
#include <algorithm>
#include <assert.h>
using namespace std;namespace wyj
{//這是第一個類 ListNode//所謂的類就是把成員對象和成員函數封裝在一起.//這個全部弄成共有//供后面存儲數據來用template<class T>struct ListNode{ListNode<T>* _next;ListNode<T>* _prev;T _data;//const T& data是接受常量//不能權限放大,會報錯ListNode(const T& data = T()):_next(nullptr),_prev(nullptr),_data(data){}};//Ref引用//Ptr指針template<class T,class Ref,class Ptr>struct  ListIterator{typedef ListNode<T> Node;typedef ListIterator<T,Ref,Ptr> Self;public:Node* _node;ListIterator(Node* node):_node(node){}//拷貝構造和賦值寫也可以,不寫也可以//這兒是淺拷貝ListIterator(const Self& it){_node = it._node;}//++itSelf& operator++(){_node = _node->_next;return *this;}Self& operator++(int){Self tmp(*this);_node = _node->_next;return tmp;}Self& operator--(){_node = _node->_prev;return *this;}Self& operator--(int){Self tmp(*this);_node = _node->_prev;return tmp;}//T* operator->()//{//	return &(_node->_data);//}Ptr operator->(){return &(_node->_data);}////這個是前置//T& operator*()//{//	return _node->_data;//}//這個是前置Ref operator*(){return _node->_data;}bool operator!=(const Self& it){return _node != it._node;}bool operator==(const Self& it){return _node == it._node;}};//template<class T>//class ListConstIterator//{//	typedef ListNode<T> Node;//	typedef ListConstIterator<T> Self;//	Node* _node;//public://	ListConstIterator(Node* node)//		:_node(node)//	{}//	//拷貝構造和賦值寫也可以,不寫也可以//	//這兒是淺拷貝//	ListConstIterator(const Self& it)//	{//		_node = it._node;//	}//	//++it//	Self& operator++()//	{//		_node = _node->_next;//		return *this;//	}//	Self& operator++(int)//	{//		Self tmp(*this);//		_node = _node->_next;//		return tmp;//	}//	Self& operator--()//	{//		_node = _node->_prev;//		return *this;//	}//	Self& operator--(int)//	{//		Self tmp(*this);//		_node = _node->_prev;//		return tmp;//	}//	const T* operator->()//	{//		return &(_node->_data);//	}//	//這個是前置//	const T& operator*()//	{//		return _node->_data;//	}//	bool operator!=(const Self& it)//	{//		return _node != it._node;//	}//	bool operator==(const Self& it)//	{//		return _node == it._node;//	}//};template<class T >class list{//封裝成私有,只能list內部用typedef ListNode<T> Node;public://ListIterator通過傳節點對節點進一步處理//typedef ListIterator<T> iterator;//typedef ListConstIterator<T> const_iterator;typedef ListIterator<T,T&,T*> iterator;typedef ListIterator<T,const T&,const T*> const_iterator;iterator begin(){//iterator it(_head->_next);//return it;//匿名對象//iterator這個類把這個節點封裝了,通過傳這個節點給iterator//調用iterator的構造函數,把節點給iterator中的_nodereturn iterator(_head->_next);}iterator end(){return iterator(_head);}const_iterator begin()  const{//iterator it(_head->_next);//return it;//匿名對象return const_iterator(_head->_next);}const_iterator end()  const{return const_iterator(_head);}void empty_init(){_head = new Node;_head->_next = _head;_head->_prev = _head;}list(){_head = new Node;_head->_next = _head;_head->_prev = _head;// empty_init()}//拷貝構造//lt2(lt1)list(const list<T>& lt){//引入這個是弄個頭結點empty_init();for (const auto& e : lt){push_back(e);}}list(initializer_list<T>il){empty_init();for (const auto& e : il){push_back(e);}}//lt1 = lt3//lt所在的list<T>& operator= (list<T>lt){std :: swap(_head,lt._head);return *this;}~list(){//Node* cur = _head->_next;//while (cur != _head)//{//	Node* next = cur->_next;//	delete cur;//	cur = next;//}//delete _head;//_head = nullptr;clear();delete _head;_head = nullptr;}void clear(){list<T>::iterator it = begin();while (it != end()){//防止迭代器失效it = erase(it);}}void push_back(const T& x){//Node* newnode = new Node(x);//Node* tail = _head->_prev;////tail->_next = newnode;//newnode->_prev = tail;//newnode->_next = _head;//_head->_prev = newnode;insert(end(), x);}void pop_back(){erase(--end());}void push_front(const T& x){insert(begin(), x);}void pop_front(){erase(begin());}//在pos前面插入//沒有迭代器失效iterator insert(iterator pos, const T& x){Node* next = pos._node;Node* newnode = new Node(x);Node* prev = next->_prev;prev->_next = newnode;newnode->_prev = prev;newnode->_next = next;next->_prev = newnode;return iterator(newnode);}//erase后pos失效了,pos指向節點被釋放了iterator erase(iterator pos){assert(pos != end());Node* cur = pos._node;Node* next = cur->_next;Node* prev = cur->_prev;prev->_next = next;next->_prev = prev;delete cur;return iterator(next);}private:Node* _head;};void func(const list<int>& lt){list<int>::const_iterator it = lt.begin();while (it != lt.end()){cout << (*it) << " ";++it;}cout << endl;}void test_list1(){list<int>l1;l1.push_back(1);l1.push_back(2);l1.push_back(3);l1.push_back(4);l1.push_back(5);//調用begin,把節點給iterator,用iterator來接受list<int>::iterator it = l1.begin();while (it != l1.end()){cout << (*it) << " ";*it += 10;++it;}cout << endl;for (auto e : l1){cout << e << " ";++it;}cout << endl;}struct Pos{Pos(int row =0,int col = 0):_row(row),_col(col){}int _row;int _col; };void test_list2(){list<Pos>lt1;lt1.push_back(Pos(100, 100));lt1.push_back(Pos(200, 200));lt1.push_back(Pos(300, 400));list<Pos>::iterator it = lt1.begin();while (it != lt1.end()){//為了可讀性,省略了一個箭頭cout << it->_row << ":"<<it->_col<<endl;//cout << it.operator->()->_row << ":" << it.operator->()->_col << endl;++it;}}void test_list3(){list<int>l1;l1.push_back(1);l1.push_back(2);l1.push_back(3);l1.push_back(4);l1.push_back(5);func(l1);cout << endl;l1.push_front(10);l1.push_front(10);l1.push_front(10);func(l1);cout << endl;l1.pop_front();l1.pop_front();func(l1);cout << endl;l1.pop_back();l1.pop_back();func(l1);cout << endl;}void test_list4(){list<int>lt1;lt1.push_back(1);lt1.push_back(2);lt1.push_back(3);lt1.push_back(4);lt1.push_back(5);func(lt1);list<int> lt2(lt1);func(lt2);list<int> lt3;lt3 = lt1;func(lt2);}void test_list5(){list<int> lt1 = { 1,2,3,4,5,6 };func(lt1);}
}
#include "list.h"
#include "list1.h"
void test_list1()
{list<int> lt1 = { 10,2,3,3,4,5,6 };list<int> ::iterator it = lt1.begin();while (it != lt1.end()){cout << *it << " ";it++;}cout << endl;//list不支持sort//sort(lt1.begin(), lt1.end(), greater<int>());//list有自己的排序算法lt1.sort();it = lt1.begin();while (it != lt1.end()){cout << *it << " ";it++;}cout << endl;lt1.sort(greater<int>());it = lt1.begin();while (it != lt1.end()){cout << *it << " ";it++;}cout << endl;//unique 去重//先排序,在去重lt1.unique();for (auto e : lt1){cout << e << " ";  //10 6 5 4 3 2}cout << endl;
}void test_list2()
{//splice:粘接std::list<int> mylist1, mylist2;std::list<int>::iterator it;// set some initial values:for (int i = 1; i <= 4; ++i)mylist1.push_back(i);      // mylist1: 1 2 3 4for (int i = 1; i <= 3; ++i)mylist2.push_back(i * 10);   // mylist2: 10 20 30it = mylist1.begin();++it;                         // points to 2mylist1.splice(it, mylist2); // mylist1: 1 10 20 30 2 3 4// mylist2 (empty)// "it" still points to 2 (the 5th element
}void test_list3()
{list<int> mylist;for (int i = 1; i <= 4; i++){mylist.push_back(i);  //mylist:   1 2 3 4} //想把3轉移到頭list<int>::iterator  it = find(mylist.begin(), mylist.end(), 3);//void splice (const_iterator position, list& x, const_iterator i);//把list的第i個位置的數粘接到position位置mylist.splice(mylist.begin(), mylist, it);
}int main()
{//wyj::test_list5();//test_list1();bit::list_test1();return 0;
} 

?/*****************************************************/

?/*****************************************************/

?下來練習代碼

#define  _CRT_SECURE_NO_WARNINGS 1
#pragma once
#include <iostream>
#include <assert.h>
using namespace std;//先定義一個節點類
//所謂的類就是把成員變量和成員方法封裝在一起
//例如這個節點類
//成員變量是指定義節點的變量,方法是指操作這個節點的方法
//那么通過成員變量和成員方法把這個節點類封裝好之后,外面該怎么用呢?
//類可以理解為就是個新定義的數據類型,那么其它類使用,則在另一個類
//中定義這個類來使用
//比如:在另一個類中使用這個節點類,則在這個類中定義即可,并且你在
//這個類中定義一個節點類,會自動初始化,銷毀,這是類的一個特性namespace wyj
{template<class T>struct ListNode{//定義數據ListNode<T>*  _prev;ListNode<T>*  _next;T _data;//初始化ListNode(const T& data = T()):_prev(nullptr),_next(nullptr),_data(data){}//拷貝構造ListNode(const ListNode& node){_prev = node._prev;_next = node._next;_data = node._data;}//賦值ListNode& operator=(const ListNode& node){_prev = node._prev;_next = node._next;_data = node._data;return *this;}};//在這兒,把ListNode要封裝一下,符合iterator的特性template<class T,class Ref>class ListIterator{//要封裝節點,首先要把節點引進進來typedef ListNode<T> Node;typedef ListIterator<T, Ref> Self;public://ListIterator(Node* node = nullptr):_node(node){}ListIterator(const Self& iterator){_node = iterator._node;}ListIterator& operator=(const Self& iterator){_node = iterator._node;return *this;}ListIterator& operator++(){_node = _node->_next;return *this;}ListIterator operator++(int){ListIterator tmp = *this;_node = _node->_next;return tmp;}ListIterator& operator--(){_node = _node->_prev;return *this;}ListIterator operator--(int){ListIterator tmp = *this;_node = _node->_prev;return tmp;}Ref operator*()  {return _node->_data;}bool operator!=(const Self& iterator){return  _node != iterator._node;}bool operator==(const Self& iterator){return  _node == iterator._node;}//private:public:Node* _node;};template<class T>class list{private://這兒把封裝好的ListNode重命名//ListNode可以理解為一種新的數據類型typedef ListNode<T> Node;public:typedef ListIterator<T,T&> iterator;typedef ListIterator<T,const T&> const_iterator;iterator begin(){return iterator(_head->_next);}iterator end(){return iterator(_head);}const_iterator begin() const{return const_iterator(_head->_next);}const_iterator end() const{return const_iterator(_head);}//寫構造函數list(){//調用了Node的構造函數_head = new Node;_head->_prev = _head;_head->_next = _head;}template<class InputIterator>list(InputIterator first, InputIterator last){init_empty();while (first != last){push_back(*first);first++;}}list(initializer_list<T> il){init_empty();for (const auto& e : il){push_back(e);}}void init_empty(){_head = new Node;_head->_prev = _head;_head->_next = _head;}list(const list<T>& lt){init_empty();for (auto& e : lt){push_back(e);}}~list(){clear();delete _head;_head = nullptr;}//犯了一個錯誤,要加換了,還const//list& operator=(const list lt)list<T>& operator=(list<T> lt){swap(_head,lt._head);return *this;}void clear(){iterator it = begin();while (it != end()){it = erase(it);}}//插入void push_back(const T& data ){Node* newnode = new Node(data);Node* tail = _head->_prev;//  tail newnode _headtail->_next = newnode;newnode->_prev = tail;newnode->_next = _head;_head->_prev = newnode;//insert(end(), data);}void pop_back(){erase(--end());}void push_front(const T& data){insert(begin(),data);}void pop_front(){erase(begin());}//在pos前面插入void insert(iterator pos, const T& data){Node* newnode = new Node(data);Node* cur = pos._node;Node* prev = cur->_prev;//prev  newnode curprev->_next = newnode;newnode->_prev = prev;newnode->_next = cur;cur->_prev = newnode;}iterator erase(iterator pos){assert(pos != end());Node* cur = pos._node;Node* prev = cur->_prev;Node* next = cur->_next;prev->_next = next;next->_prev = prev;delete cur;return iterator(next);}private:Node* _head;};void list_test1(){list<int> lt1;lt1.push_back(1);lt1.push_back(2);lt1.push_back(3);lt1.push_back(4);list<int>::iterator it = lt1.begin();for (auto e : lt1){cout << e << " ";}cout << endl;while (it != lt1.end()){(*it) += 10;it++;}for (auto e : lt1){cout << e << " ";}}void Func(const list<int>& lt){list<int>::const_iterator it = lt.begin();while (it != lt.end()){cout << (*it) << " ";it++;}cout << endl;}void list_test2(){list<int> lt1;lt1.push_back(1);lt1.push_back(2);lt1.push_back(3);lt1.push_back(4);lt1.push_back(5);Func(lt1);lt1.push_front(10);lt1.push_front(20);lt1.push_front(30);Func(lt1);lt1.pop_front();lt1.pop_front();Func(lt1);lt1.pop_back();lt1.pop_back();Func(lt1);lt1.pop_back();lt1.pop_back();lt1.pop_back();lt1.pop_back();//lt1.pop_back();Func(lt1);}void list_test3(){//構造函數list<int> lt1 = { 1,2,3,4,5,6,7,8 };for (auto& e : lt1){cout << e << " ";}cout << endl;list<int> lt2 = lt1;for (auto& e : lt1){cout << e << " ";}cout << endl;list<int>lt3;lt3 = lt1;for (auto& e : lt1){cout << e << " ";}cout << endl;}
}

?
?
?
?

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

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

相關文章

在CentOS 7上將PostgreSQL數據庫從默認路徑遷移到自定義目錄

在CentOS 7上將PostgreSQL數據庫從默認路徑遷移到自定義目錄&#xff0c;需遵循以下步驟。假設原數據目錄為“/var/lib/pgsql/12/data”&#xff0c;目標目錄為“/new/path/pgdata”。 1、步驟概覽 停止PostgreSQL服務創建新目錄并設置權限復制數據文件&#xff08;保留權限&am…

C語言基礎06——結構體(struct)

一、結構體的概念結構體&#xff08;struct&#xff09;是 C 語言中一種自定義數據類型&#xff0c;它允許你將不同類型的數據項組合在一起&#xff0c;形成一個新的復合數據類型。想象一下&#xff1a;如果要表示一個 "學生"&#xff0c;需要包含姓名&#xff08;字…

小白入門指南:Edge SCDN 輕松上手

在互聯網飛速發展的當下&#xff0c;網站性能與安全至關重要。對于小白而言&#xff0c;Edge SCDN 可能是個陌生概念&#xff0c;但它卻能極大助力網站運營。本文將用簡單易懂的語言&#xff0c;帶大家了解 Edge SCDN&#xff0c;探討其運用方法。?一、Edge SCDN 是什么&#…

探秘酵母單雜交技術:解鎖基因調控的密碼

在生命科學研究領域&#xff0c;基因的表達調控機制一直是科學家們關注的焦點。為了深入探究這一復雜過程&#xff0c;眾多先進技術應運而生&#xff0c;酵母單雜交技術便是其中極具價值的一項&#xff0c;它為研究 DNA 與蛋白質之間的相互作用提供了獨特視角與有效手段。酵母單…

大模型備案要點一次過【附材料清單詳解】

最近&#xff0c;廣東省公布了最新一批的大模型備案&#xff08;登記&#xff09;名單&#xff0c;很多準備要做大模型備案的企業都在紛紛咨詢&#xff1a;“大模型備案的周期是多久&#xff1f;”“做大模型備案有什么要求&#xff1f;”“做大模型備案一共需要準備多少材料&a…

啟保停-----------單相照明燈的接法

一.單相照明燈-K21使用的器材,單相電能表,空開,插座,開關,燈泡二.啟 保 停1.需要用到的器材1.空開2.三相電機3.接觸器4.熔斷器5.按鈕2.電路的作用按按鈕 運轉 在按按鈕 停止運轉3.電動4.加上輔助觸點 控制電路5.在加上按鈕 停止電路

TF-IDF:信息檢索與文本挖掘的統計權重基石

本文由「大千AI助手」原創發布&#xff0c;專注用真話講AI&#xff0c;回歸技術本質。拒絕神話或妖魔化。搜索「大千AI助手」關注我&#xff0c;一起撕掉過度包裝&#xff0c;學習真實的AI技術&#xff01; 1. 背景與定義 TF-IDF 是一種統計加權方法&#xff0c;用于衡量詞語在…

[論文閱讀] (41)JISA24 物聯網環境下基于少樣本學習的攻擊流量分類

《娜璋帶你讀論文》系列主要是督促自己閱讀優秀論文及聽取學術講座&#xff0c;并分享給大家&#xff0c;希望您喜歡。由于作者的英文水平和學術能力不高&#xff0c;需要不斷提升&#xff0c;所以還請大家批評指正&#xff0c;非常歡迎大家給我留言評論&#xff0c;學術路上期…

react中父子數據流動和事件互相調用(和vue做比較)

前言&#xff1a;react中父子數據流動和事件互相調用&#xff0c;父組件給子組件數據&#xff0c;父組件調用子組件的事件&#xff0c;同理&#xff0c;子也可以調用父的數據和傳值。react是單向數據流&#xff0c;具體使用跟vue是不同的。1、父組件的數據傳給子組件&#xff0…

杰理手表-增加提示音-提示音音量調整--使用提示音

本章節非常詳細的介紹這個提示音的增加-調整-使用&#xff0c;其余耳機包之類的也是差不多的&#xff01;&#xff01; 目錄 1.添加自己需要用的提示音 2.根據添加的提示音-代碼中配置 1.在tone_player.h中枚舉里添加本次提示音的名稱 2.把定義好的提示音放到tone_player.…

數據庫的基本操作(視圖,存儲,觸發器)

1、視圖&#xff08;1&#xff09;什么是視圖視圖是虛擬表&#xff0c;是基于查詢結果的可視化表&#xff0c;視圖的作用有&#xff1a;①簡化復雜查詢 ②限制數據訪問 ③提供數據獨立性 ④匯總數據&#xff08;2&#xff09;怎么創建視圖創建視圖 CREATE OR REPLACE VIEW 視圖…

Pytest項目_day13(usefixture方法、params、ids)

usefixture 我們還可以使用mark.usefixtures來調用fixture 這樣相比在傳入參數處調用fixture&#xff0c;會更加直接 但是如果我們在一個測試用例中使用了多個usefixtures&#xff0c;那么測試用例會先調用離他最近的那個fixtureparams fixture中還可以帶參數 當我們用request.…

Rust 異步生態實戰:Tokio 調度、Pin/Unpin 與零拷貝 I/O

&#x1f31f; Hello&#xff0c;我是蔣星熠Jaxonic&#xff01; &#x1f308; 在浩瀚無垠的技術宇宙中&#xff0c;我是一名執著的星際旅人&#xff0c;用代碼繪制探索的軌跡。 &#x1f680; 每一個算法都是我點燃的推進器&#xff0c;每一行代碼都是我航行的星圖。 &#x…

通用 maven 私服 settings.xml 多源配置文件(多個倉庫優先級配置)

<?xml version"1.0" encoding"UTF-8"?> <settings xmlns"http://maven.apache.org/SETTINGS/1.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://maven.apache.org/SETTINGS/1.0.…

AT F-Intervals 題解

簡化題意&#xff1a; 有 nnn 個區間&#xff0c;保證所有區間同時覆蓋一個點&#xff0c;每次將區間平移一個單位&#xff0c;問使得區間兩兩不交的最小操作數&#xff08;端點處可重疊&#xff09;。n≤5000。l,r≤231?1n\leq 5000。l,r\leq 2^{31}-1n≤5000。l,r≤231?1。…

《飛算Java AI:從安裝到需求轉實戰項目詳細教學》

前引&#xff1a;在當今快速發展的技術環境中&#xff0c;人工智能&#xff08;AI&#xff09;與編程語言的結合為開發者提供了前所未有的便利。飛算Java AI作為一款智能化編程工具&#xff0c;能夠顯著提升Java開發效率&#xff0c;減少重復性工作&#xff0c;并幫助開發者更專…

6深度學習Pytorch-神經網絡--過擬合欠擬合問題解決(Dropout、正則化、早停法、數據增強)、批量標準化

過擬合、欠擬合 在機器學習和深度學習中&#xff0c;過擬合&#xff08;Overfitting&#xff09;和欠擬合&#xff08;Underfitting&#xff09;是模型訓練過程中常見的兩種問題&#xff0c;直接影響模型的泛化能力&#xff08;即對未見過的數據的預測能力&#xff09;。 1. 欠…

新手向:Python編寫簡易翻譯工具

Python 編寫簡易翻譯工具&#xff1a;從零開始入門指南對于剛接觸編程的新手來說&#xff0c;編寫一個實用的工具是快速入門的好方法。本文將詳細介紹如何用 Python 編寫一個簡易的翻譯工具&#xff0c;幫助理解基礎編程概念和實際應用。無需任何編程基礎&#xff0c;只需按照步…

爬蟲與數據分析結和

任務描述 爬取目標&#xff1a;高三網中國大學排名一覽表&#xff0c;網址為 2021中國的大學排名一覽表_高三網。爬取內容&#xff1a;學校名稱、總分、全國排名、星級排名、辦學層級。數據存儲&#xff1a;爬取后的數據保存在 CSV 文件中。 代碼實現&#xff08;爬取&#xff…

linux下安裝php

1.php官網下載所需要的php版本 下載php 2.將下載好的壓縮包上傳至linux服務器&#xff0c;解壓并配置 tar -xzvf php-8.4.11.tar.gz cd php-8.4.11 ./configure --prefix/home/admintest/php/php-8.4.11 # 配置安裝路徑和選項 make sudo make install3.使用make命令編譯完成…