29 线性表 · 队列

news2024/9/21 22:58:20

目录

一、概念与结构

(一)概念

1、队列

2、入队列

3、出队列

(二)底层结构

二、队列的实现

三、队列的算法题

(一)用队列实现栈

(二)用栈实现队列

(三)设计循环队列

1、循环队列的概念与结构

2、题目 


一、概念与结构

(一)概念

1、队列

        只允许在一端进行插入数据操作,在另一端进行删除数据操作的特殊线性表,队列具有先进先出的原则。

2、入队列

        进行插入操作的一端称为队尾。

3、出队列

        进行删除操作的一端称为队头。

(二)底层结构

        可以使用数组或者单链表实现队列。

        数组:在队尾使用尾插方便,时间复杂度为O(1),但是队头出数据后,所有数据都要向前移动一位,最差的情况下时间复杂度为O(N)。

        单链表: 以头节点为队头,出数据的时间复杂度为O(1),而在链表插入数据,则要先循环找到最后一个节点,时间复杂度为O(N)。可以改进:设置头指针与尾指针,这样出数据与入数据的时间复杂度均为O(1)。

        综上所述,底层使用多设置一个尾指针的单链表更好。

二、队列的实现

        队列的常用名:Queue。

队列的编写:

① 头文件:定义队列的结构体,声明要提供的操作(起到目录作用)。

② cpp文件:编写具体实现各种操作(起到内容作用)。

③ 测试文件:测试是否可以正常运行。

Queue.h

#pragma once
#include<stdlib.h>
#include<assert.h>
#include<iostream>
#include<stdbool.h>
using namespace std;

typedef int QDataType;
typedef struct QueueNode
{
	QDataType data;
	struct QueueNode* next;
}QueueNode;

struct Queue
{
	QueueNode* phead;
	QueueNode* ptail;
	int size;//储存队列的有效数据
};

//一、初始化队列,判断是否为空,取有效元素个数,销毁队列
//(一)初始化队列
void QueueInit(Queue& q);
//(二)判断是否为空
bool QueueEmpty(Queue& q);
//(三)取有效元素个数
int QueueSize(Queue q);
//(四)销毁队列
void QueueDestroy(Queue& q);

//二、队尾入数据,队头出数据
//(一)队尾入数据
void QueuePush(Queue& q, QDataType num);
//(二)队头出数据
void QueuePop(Queue& q);

//三、取队头、队尾数据
//(一)取队头数据
QDataType QueueGetHead(Queue& q);
//(二)取队尾数据
QDataType QueueGetTail(Queue& q);

Queue.cpp

#define _CRT_SECURE_NO_WARNINGS 1
#include"Queue.h"

//一、初始化队列,判断是否为空,取有效元素个数,销毁队列
//(一)初始化队列
void QueueInit(Queue& q)
{
	q.phead = q.ptail = nullptr;
	q.size = 0;
}
//(二)判断是否为空
bool QueueEmpty(Queue& q)
{
	return q.phead == nullptr && q.ptail == nullptr;
}
//(三)取有效元素个数
int QueueSize(Queue q)
{
	return q.size;
}
//(四)销毁队列
void QueueDestroy(Queue& q)
{
	assert(!QueueEmpty(q));
	QueueNode* pcur = q.phead;
	while (pcur)
	{
		QueueNode* next_node = pcur->next;
		free(pcur);
		pcur = next_node;
	}
	q.phead = q.ptail = nullptr;
	q.size = 0;
}

//二、队尾入数据,队头出数据
//(一)队尾入数据
void QueuePush(Queue& q, QDataType num)
{
	//创建队列节点
	QueueNode* new_node = (QueueNode*)malloc(sizeof(QueueNode));
	if (new_node == nullptr)
	{
		perror("QueuePush malloc fail!");
		exit(1);
	}
	new_node->data = num;
	new_node->next = nullptr;

	//插入队尾,尾插有两种情况:头节点为空与不为空
	if (q.phead == nullptr && q.ptail == nullptr)
		q.phead = q.ptail = new_node;
	else
	{
		q.ptail->next = new_node;
		q.ptail = new_node;
	}
	q.size++;
}
//(二)队头出数据
void QueuePop(Queue& q)
{
	assert(!QueueEmpty(q));
	//需要考虑队列中只有一个节点的情况和多个节点的情况
	if (q.phead == q.ptail)
	{
		free(q.phead);
		q.phead = q.ptail = nullptr;
	}
	else
	{
		QueueNode* next_node = q.phead->next;
		free(q.phead);
		q.phead = next_node;
	}
	q.size--;
}

//三、取队头、队尾数据
//(一)取队头数据
QDataType QueueGetHead(Queue& q)
{
	assert(!QueueEmpty(q));
	return q.phead->data;
}
//(二)取队尾数据
QDataType QueueGetTail(Queue& q)
{
	assert(!QueueEmpty(q));
	return q.ptail->data;
}

test.cpp

#define _CRT_SECURE_NO_WARNINGS 1
#include"Queue.h"

void QueueTest01()
{
	Queue q;
	QueueInit(q);

	for (int i = 1; i < 11; i++)
	{
		QueuePush(q, i);
	}

	/*for (int i = 1; i < 11; i++)
	{
		QueuePop(q);
	}*/
	cout << "QueueSize: " << QueueSize(q) << endl;

	QueueDestroy(q);
	cout << "QueueSize: " << QueueSize(q) << endl;
}

int main()
{
	QueueTest01();
	return 0;
}

        注意:

                与栈一样,不能通过下标进行随机访问其中的数据,所以不能被遍历。

三、队列的算法题

(一)用队列实现栈

        题目链接如下:

                https://leetcode.cn/problems/implement-stack-using-queues/description/

        解题思路:

                假设队列Q1中有三个数据:

                ① 把队列Q1的前两个数据出队列,插入到Q2队列中,再单独拿出Q1队列的最后一个数据,相当于栈的最后一个元素先出;

                ② 把队列Q2的第一个元素出队列,插入到Q1队列中,再单独拿出Q2队列的最后一个数据,相当于栈的倒数第二个元素出栈。

                ③ 再把队列不为空的Q1出队列。

        总结:

                出栈思路 :找不为空的队列,将size-1个数据导入到另一个队列中。

                入栈思路:往不为空队列中插入数据。

                取栈顶元素: 与出栈操作的区别就是不需要将栈顶元素出栈,直接返回即可;但这样会导致队列中最后一个元素不出栈,让两个队列都不为空,这样不行。解决:找不为空的队列,取队尾。(必须保证至少一个队列为空)

        答案代码如下:

//定义队列结构
typedef int QDataType;
typedef struct QueueNode
{
	QDataType data;
	struct QueueNode* next;
}QueueNode;

typedef struct Queue
{
	QueueNode* phead;
	QueueNode* ptail;
	int size;//保存队列有效数据个数
}Queue;

//初始化队列
void QueueInit(Queue* pq)
{
	assert(pq);
	pq->phead = pq->ptail = NULL;
	pq->size = 0;
}
// ⼊队列,队尾
void QueuePush(Queue* pq, QDataType x)
{
	assert(pq);
	//申请新节点
	QueueNode* newnode =(QueueNode*)malloc(sizeof(QueueNode));
	if (newnode == NULL)
	{
		perror("malloc fail!");
		exit(1);
	}
	newnode->data = x;
	newnode->next = NULL;

	//ptail newnode
	if (pq->phead == NULL)
	{//队列为空
		pq->phead = pq->ptail = newnode;
	}
	else
	{
		//队列不为空
		pq->ptail->next = newnode;
		pq->ptail = pq->ptail->next;//newnode
	}
	pq->size++;
}

//队列判空
bool QueueEmpty(Queue* pq)
{
	assert(pq);
	return pq->phead == NULL && pq->ptail == NULL;
}

// 出队列,队头
void QueuePop(Queue* pq)
{
	assert(pq);
	assert(!QueueEmpty(pq));

	//只有一个结点的情况,避免ptail变成野指针
	if (pq->ptail == pq->phead)
	{
		free(pq->phead);
		pq->phead = pq->ptail = NULL;
	}
	else
	{
		//删除队头元素、
		QueueNode* next = pq->phead->next;
		free(pq->phead);
		pq->phead = next;
	}
	--pq->size;
}
//取队头数据
QDataType QueueFront(Queue* pq)
{
	assert(pq);
	assert(!QueueEmpty(pq));

	return pq->phead->data;
}

//取队尾数据
QDataType QueueBack(Queue* pq)
{
	assert(pq);
	assert(!QueueEmpty(pq));

	return pq->ptail->data;
}
//队列有效元素个数
int QueueSize(Queue* pq)
{
	assert(pq);
	/*int size = 0;
	QueueNode* pcur = pq->phead;
	while (pcur)
	{
		size++ ;
		pcur = pcur->next;
	}
	return size;*/
	return pq->size;
}

//销毁队列
void QueueDestroy(Queue* pq)
{
	assert(pq);
	//assert(!QueueEmpty(pq));

	QueueNode* pcur = pq->phead;
	while (pcur)
	{
		QueueNode* next = pcur->next;
		free(pcur);
		pcur = next;
	}
	pq->phead = pq->ptail = NULL;
	pq->size = 0;
}

//两个队列实现一个栈
typedef struct {
    Queue q1;
    Queue q2;
} MyStack;

//初始化
MyStack* myStackCreate() {
    MyStack* obj= (MyStack*)malloc(sizeof(MyStack));
    QueueInit(&obj->q1);
    QueueInit(&obj->q2);

    return obj;
}

//入栈
void myStackPush(MyStack* obj, int x) {
    if(!QueueEmpty(&obj->q1))
        QueuePush(&obj->q1, x);
    else
        QueuePush(&obj->q2, x);
}

//出栈
int myStackPop(MyStack* obj) {
    //找不为空的队列
    Queue* empQ = &obj->q1;//队列为空的指针
    Queue* noneQ = &obj->q2;//队列不为空的指针
    if(!QueueEmpty(&obj->q1))
    {
        empQ = &obj->q2;
        noneQ = &obj->q1;
    }

    //将size-1个数据插入到另一个队列中
    while(QueueSize(noneQ) > 1)
    {
        QDataType Front = QueueFront(noneQ);
        QueuePush(empQ, Front);
        QueuePop(noneQ);
    }

    //记录返回队头元素,然后出队队头元素
    QDataType re = QueueFront(noneQ);
    QueuePop(noneQ);
    return re;
}

//取栈顶元素
int myStackTop(MyStack* obj) {
    if(!QueueEmpty(&obj->q1))
        return QueueBack(&obj->q1);
    else
        return QueueBack(&obj->q2);
}

//判断是否为空
bool myStackEmpty(MyStack* obj) {
    return QueueEmpty(&obj->q1) && QueueEmpty(&obj->q2);
}

//销毁栈
void myStackFree(MyStack* obj) {
    QueueDestroy(&obj->q1);
    QueueDestroy(&obj->q2);
    free(obj);
    obj = NULL;
}

/**
 * Your MyStack struct will be instantiated and called as such:
 * MyStack* obj = myStackCreate();
 * myStackPush(obj, x);
 
 * int param_2 = myStackPop(obj);
 
 * int param_3 = myStackTop(obj);
 
 * bool param_4 = myStackEmpty(obj);
 
 * myStackFree(obj);
*/

(二)用栈实现队列

        题目链接如下:

                https://leetcode.cn/problems/implement-queue-using-stacks/description/

        解题思路:        

                ① 入队:往pushST中插入数据

                ② 出队:判断popST是否为空或,不为空直接pop;为空则将pushST导入到popST中再pop。

                ③ 跟出队一样,但是步pop数据

        注意点:

                必须保证至少一个队列为空。

        答案代码如下:

typedef int STDataType;
typedef struct Stack
{
	STDataType* arr;
	int capacity;     //栈的空间大小
	int top;          //栈顶
}ST;

//栈的初始化
void STInit(ST* ps)
{
	assert(ps);
	ps->arr = NULL;
	ps->capacity = ps->top = 0;
}

//销毁栈
void STDestroy(ST* ps)
{
	assert(ps);
	if (ps->arr)
		free(ps->arr);
	ps->arr = NULL;
	ps->top = ps->capacity = 0;
}

//入栈
void StackPush(ST* ps, STDataType x)
{
	assert(ps);
	
	//1.判断空间是否足够
	if (ps->capacity == ps->top)
	{
		int newCapacity = ps->capacity == 0 ? 4 : 2 * ps->capacity;
		STDataType* tmp = (STDataType*)realloc(ps->arr, newCapacity * sizeof(STDataType));
		if (tmp == NULL)
		{
			perror("realloc fail!");
			exit(1);
		}
		ps->arr = tmp;
		ps->capacity = newCapacity;
	}
	//空间足够
	ps->arr[ps->top++] = x;
}

//判断栈是否为空
bool StackEmpty(ST* ps)
{
	assert(ps);
	return ps->top == 0;
}

//出栈
void StackPop(ST* ps)
{
	assert(ps);
	assert(!StackEmpty(ps));

	--ps->top;
}

//取栈顶元素
STDataType StackTop(ST* ps)
{
	assert(ps);
	assert(!StackEmpty(ps));

	return ps->arr[ps->top - 1];
}

//获取栈中有效元素个数
int STSize(ST* ps)
{
	assert(ps);
	return ps->top;
}

typedef struct {
    ST pushST;
    ST popST;
} MyQueue;

//初始化队列
MyQueue* myQueueCreate() {
    MyQueue* obj = (MyQueue*)malloc(sizeof(MyQueue));
    STInit(&obj->pushST);
    STInit(&obj->popST);

    return obj;
}

//插入数据
void myQueuePush(MyQueue* obj, int x) {
    StackPush(&obj->pushST, x);
}

//删除数据
int myQueuePop(MyQueue* obj) {
    //popST有数据则直接删,若没有则从pushST中导入数据再删
    //① 导数据
    if(StackEmpty(&obj->popST))
    {
        while(!StackEmpty(&obj->pushST))
        {
            StackPush(&obj->popST, StackTop(&obj->pushST));
            StackPop(&obj->pushST);
        }
    }

    //② 删
    STDataType re = StackTop(&obj->popST);
    StackPop(&obj->popST);
    return re;
}

//取队头元素
int myQueuePeek(MyQueue* obj) {
    if(StackEmpty(&obj->popST))
    {
        while(!StackEmpty(&obj->pushST))
        {
            StackPush(&obj->popST, StackTop(&obj->pushST));
            StackPop(&obj->pushST);
        }
    }
    return StackTop(&obj->popST);
}

//判断队列是否为空
bool myQueueEmpty(MyQueue* obj) {
    return StackEmpty(&obj->popST) && StackEmpty(&obj->pushST);
}

//销毁队列
void myQueueFree(MyQueue* obj) {
    STDestroy(&obj->popST);
    STDestroy(&obj->pushST);
    free(obj);
    obj = NULL;
}

/**
 * Your MyQueue struct will be instantiated and called as such:
 * MyQueue* obj = myQueueCreate();
 * myQueuePush(obj, x);
 
 * int param_2 = myQueuePop(obj);
 
 * int param_3 = myQueuePeek(obj);
 
 * bool param_4 = myQueueEmpty(obj);
 
 * myQueueFree(obj);
*/

(三)设计循环队列

1、循环队列的概念与结构

                ① 概念:有一种特殊的队列叫环形队列,环形队列首位相连成环,环形队列可以使用数组或者链表进行实现。

                ② 结构:如下所示:

2、题目 

        题目链接如下:

                https://leetcode.cn/problems/design-circular-queue/description/

        解题思路:

                ① 循环队列更推荐使用数组,因为若是使用单链表来实现要申请多个空间并且有指针的消耗。链表的节点还要多设置一个状态属性来标明该节点是否为空以判断能否插入,这样会很麻烦。

                ② front == rear 既可以判断空间为满和空间为空,怎么区分?多申请一块空间。假设能存放数据的空间大小为4(k = 4),申请5块空间,当 (rear + 1) % (k + 1) == front 则空间已满(5%5 = 0),这里取余是为了rear到了最后一个元素的时候 + 1 会超出申请空间的个数,取余可以解决这个问题,让超出的位置循环回到数组对应的位置。所以用 rear == front 判断为空。        

        注意点:

                ① 循环队列空间固定。

                ② 循环队列满了,就不能插入数据。

         答案代码如下:



//定义循环队列的结构
typedef struct {
    int* arr;
    int front;//头下标
    int rear;//尾下标
    int capecity;//数组最大元素个数

} MyCircularQueue;

//初始化空间大小 
MyCircularQueue* myCircularQueueCreate(int k) {
    MyCircularQueue* obj = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
    obj->arr = (int*)malloc(sizeof(int) * (k + 1));
    obj->front = obj->rear = 0;
    obj->capecity = k;

    return obj;
}

//判断队列是否满
bool myCircularQueueIsFull(MyCircularQueue* obj) {
    return (obj->rear + 1)%(obj->capecity + 1) == obj->front; 
}

//插入数据
bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {
    //需要先判断空间是否已经满了 
    if(myCircularQueueIsFull(obj))
        return false;
    else
    {
        obj->arr[obj->rear++] = value;
        obj->rear %= obj->capecity + 1;
        return true;
    }
}

//判断队列是否为空
bool myCircularQueueIsEmpty(MyCircularQueue* obj) {
    return obj->rear == obj->front;
}

//删除数据
bool myCircularQueueDeQueue(MyCircularQueue* obj) {
    if(myCircularQueueIsEmpty(obj))
        return false;
    else
    {
        obj->front++;
        obj->front %= obj->capecity + 1;
        return true;
    }
}

//取队首元素
int myCircularQueueFront(MyCircularQueue* obj) {
    if(myCircularQueueIsEmpty(obj))
        return -1;
    else
        return obj->arr[obj->front];
}

//取队尾元素
int myCircularQueueRear(MyCircularQueue* obj) {
    if(myCircularQueueIsEmpty(obj))
        return -1;
    else
    {
        int pre = obj->rear - 1;
        if(obj->rear == 0)
            pre = obj->capecity;
        return obj->arr[pre];
    }
}

//销毁队列
void myCircularQueueFree(MyCircularQueue* obj) {
    free(obj->arr);
    obj->arr = NULL;
    free(obj);
    obj = NULL;
}

/**
 * Your MyCircularQueue struct will be instantiated and called as such:
 * MyCircularQueue* obj = myCircularQueueCreate(k);
 * bool param_1 = myCircularQueueEnQueue(obj, value);
 
 * bool param_2 = myCircularQueueDeQueue(obj);
 
 * int param_3 = myCircularQueueFront(obj);
 
 * int param_4 = myCircularQueueRear(obj);
 
 * bool param_5 = myCircularQueueIsEmpty(obj);
 
 * bool param_6 = myCircularQueueIsFull(obj);
 
 * myCircularQueueFree(obj);
*/

        以上内容仅供分享,若有错误,请多指正。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2141908.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

基于AG32 的USB转以太网方案

如何通过USB转以太网标准模块&#xff1f; AG32支持USB FSOTG和以太网MAC&#xff0c;并且提供了标准例程&#xff0c;包括网络Lwip和USB的开发例程&#xff0c;上层应用调tinyUSB的接口即可。 以下是AG32VF407VG的引脚定义&#xff0c;支持USB外设。 LQFP-100Pin nameAG32VFx…

简单了解Maven与安装

Maven 1.Maven 简介 Maven 是 Apache 软件基金会&#xff08;国外组织&#xff0c;专门维护开源项目&#xff09;的一个开源项目, 是一个优秀的项目构建工具, 它用来帮助开发者管理项目中的 jar, 以及 jar 之间的依赖关系(在A.jar文件中用到了B.jar)、 完成项目的编译&am…

圆环加载效果

效果预览 代码实现 from PyQt5.QtCore import QSize, pyqtProperty, QTimer, Qt, QThread, pyqtSignal from PyQt5.QtGui import QColor, QPainter from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QPushButton, QVBoxLayout, QLabel, QGridLayoutclass Cir…

Rust使用Actix-web和SeaORM库开发WebAPI通过Swagger UI查看接口文档

本文将介绍Rust语言使用Actix-web和SeaORM库&#xff0c;数据库使用PostgreSQL&#xff0c;开发增删改查项目&#xff0c;同时可以通过Swagger UI查看接口文档和查看标准Rust文档 开始项目 首先创建新项目&#xff0c;名称为rusty_crab_api cargo new rusty_crab_apiCargo.t…

Nuxt Kit 中的页面和路由管理

title: Nuxt Kit 中的页面和路由管理 date: 2024/9/17 updated: 2024/9/17 author: cmdragon excerpt: 摘要:本文介绍了Nuxt Kit中页面和路由管理的高级功能,包括extendPages自定义页面路由、extendRouteRules定义复杂路由逻辑及addRouteMiddleware注册路由中间件。通过这…

Html css样式总结

1.Html css样式总结 1.1. 定位position 布局是html中非常重要的一部分&#xff0c;而定位在页面布局中也是使用频率很高的方法&#xff0c;本章节为定位在布局中的使用技巧和注意事项。   position定位有4个属性&#xff0c;分别是static(默认&#xff09;&#xff0c;absol…

第四天旅游线路预览——从换乘中心到白哈巴村

第四天&#xff1a;从贾登峪到喀纳斯风景区入口&#xff0c;晚上住宿贾登峪&#xff1b; 换乘中心有4 路车&#xff0c;喀纳斯③号车&#xff0c;去白哈巴村&#xff0c;路程时长约40分钟&#xff1b; 将上面的的行程安排进行动态展示&#xff0c;具体步骤见”Google earth st…

用Spring Boot搭建的读书笔记分享平台

第1章 绪论 1.1课题背景 计算机的普及和互联网时代的到来使信息的发布和传播更加方便快捷。用户可以通过计算机上的浏览器访问多个应用系统&#xff0c;从中获取一些可以满足用户需求的管理系统。网站系统有时更像是一个大型“展示平台”&#xff0c;用户可以选择所需的信息进入…

【Spring Security系列】如何用Spring Security集成手机验证码登录?五分钟搞定!

作者&#xff1a;后端小肥肠 &#x1f347; 我写过的文章中的相关代码放到了gitee&#xff0c;地址&#xff1a;xfc-fdw-cloud: 公共解决方案 &#x1f34a; 有疑问可私信或评论区联系我。 &#x1f951; 创作不易未经允许严禁转载。 姊妹篇&#xff1a; 【Spring Security系列…

拖拽排序的实现示例demo

拖拽排序的实现示例demo 文章说明核心代码示例效果展示 文章说明 文章主要为了学习拖拽排序的实现思路&#xff0c;并且采用此示例效果来进一步理解Flip动画的使用 参考渡一前端袁老师的讲解视频 核心代码 页面源码&#xff0c;拖拽排序的实现代码并不复杂&#xff0c;但是可以…

我的标志:奇特的头像

<!DOCTYPE html> <html lang"zh-CN"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>与妖为邻</title><style>figure.log…

C++11(4)

万众瞩目的C11特辑来了&#xff0c;本章将继续讲解C11更新的内容&#xff0c;不过C11的内容也快接近尾声了。 目录 10。lambda表达式 11。lambda捕捉列表[] 捕捉列表说明 lambda捕捉列表实际应用 10。lambda表达式 #include<iostream> using namespace std; #inclu…

手把手教你:在微信小程序中加载map并实现拖拽添加标记定位

本文将为大家详细介绍如何在微信小程序中加载map组件&#xff0c;并实现拖拽标记定位功能。 实现步骤 1、首先&#xff0c;我们需要在项目的app.json文件中添加map组件的相关配置。如下所示&#xff1a; {"pages": ["pages/index/index"],"permiss…

robomimic基础教程(三)——自带算法

robomimic自带几个高质量的离线学习算法的实现&#xff0c;包括模仿学习和强化学习&#xff0c;并提供相关工具来辅助你轻松构建自己的学习算法。 一、模仿学习&#xff08;Imitation Learning&#xff09; 1. BC (Behavioral Cloning) Vanilla Behavioral Cloning, 旨在通过…

使用knn算法对iris数据集进行分类

程序功能 使用 scikit-learn 库中的鸢尾花数据集&#xff08;Iris dataset&#xff09;&#xff0c;并基于 KNN&#xff08;K-Nearest Neighbors&#xff0c;K近邻&#xff09;算法进行分类&#xff0c;最后评估模型的准确率。 代码 from sklearn import datasets# 加载鸢尾…

链表在开空间时候出现的问题

题目&#xff1a; 第一种写法完整答案&#xff1a; 第二种写法完整答案&#xff1a;

【机器学习】--- 自监督学习

1. 引言 机器学习近年来的发展迅猛&#xff0c;许多领域都在不断产生新的突破。在监督学习和无监督学习之外&#xff0c;自监督学习&#xff08;Self-Supervised Learning, SSL&#xff09;作为一种新兴的学习范式&#xff0c;逐渐成为机器学习研究的热门话题之一。自监督学习…

【C++题解】1996. 每个小组的最大年龄

欢迎关注本专栏《C从零基础到信奥赛入门级&#xff08;CSP-J&#xff09;》 问题&#xff1a;1996. 每个小组的最大年龄 类型&#xff1a;二维数组 题目描述&#xff1a; 同学们在操场上排成了一个 n 行 m 列的队形&#xff0c;每行的同学属于一个小组&#xff0c;请问每个小…

PCIe进阶之TL:Completion Rules TLP Prefix Rules

1 Completion Rules & TLP Prefix Rules 1.1 Completion Rules 所有的 Read、Non-Posted Write 和 AtomicOp Request 都需要返回一个 Completion。Completion 有两种类型:一种带数据负载的,一种不带数据负载的。以下各节定义了 Completion header 中每个字段的规则。 C…

【磨皮美白】基于Matlab的人像磨皮美白处理算法,Matlab处理

博主简介&#xff1a;matlab图像代码项目合作&#xff08;扣扣&#xff1a;3249726188&#xff09; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 本次案例是基于Matlab的图像磨皮美白处理&#xff0c;用matlab实现。 一、案例背景和算法介绍 …