一种基于平衡二叉树(AVL树)插入、查找和删除的简易图书管理系统

目录

  • 1. 需求分析
  • 2. 项目核心设计
    • 2.1 结点插入
    • 2.2 结点删除
  • 3 测试结果
  • 4 总结分析
    • 4.1 调试过程中的问题是如何解决的,以及对设计与实现的回顾讨论和分析
    • 4.2 算法的时间和空间复杂度的分析,以及进一步改进的设想
    • 4.3 本次实验的经验和体会
  • 5 完整代码(C++)

1. 需求分析

  1. 设计和实现一个简易的图书管理系统,通过AVL树的插入、查找和删除等,完成各功能;
  2. 每种书的登记内容至少包括书号、书名、著者、现存量和总库存量等五项;
  3. 书的数据用二叉排序树存储,借阅登记信息采用顺序表—链表存储;
  4. 采编入库:新购入一种书,经分类和确定书号之后登记到图书帐目中去。如果这种书在帐中已有,则只将该书的总库存量增加。图书按登记的先后顺序入库(利用平衡二叉树实现动态查找表的插入),书号为图书的关键字。初始时,平衡二叉树为空树;
  5. 借阅:如果一种书的现存量大于零,则借出一本,登记借阅者的图书证号和归还期限。借阅者借阅图书时,先检查借阅者有无超期未归还图书,如有,则不能借阅,如无,利用平衡二叉树实现动态查找表的查找,登记借阅信息。同一种书不能重复借阅;
  6. 归还:注销对借阅者的登记,改变该书的现存量(如果借阅者归还所有的书,则注销该借阅者的信息);
  7. 清除库存:将该图书从平衡二叉树中删除,同时确保二叉树平衡;
  8. 凹入表打印平衡二叉树,同时展示结点平衡因子bf,确保插入和删除操作的正确性。

2. 项目核心设计

本程序使用C语言编写与AVL树相关的内容,故函数形参中未使用引用变量,需修改的实参均以指针形式呈现。后因图书管理系统封装函数的需求,更改.c文件为.cpp文件,从而引入class。

项目核心部分为AVL树的生成和结点删除的同时如何保证树的平衡性,下面对其实现原理进行解释。基于此,构建图书管理系统,系统逻辑和具体功能见MindMap。

系统逻辑

2.1 结点插入

对结点插入的解释以向其根结点左侧插入为例,右插类似,不做赘述。
若插入结点的关键词小于根结点的关键词,则插入根结点的左孩子。插入后,向根结点回溯时,返回一个taller,告知根结点因插入新结点而高度是否发生改变。此时分三种情况进行讨论:

  1. 若根结点原本右高(RH),则因新结点的插入而使根结点等高(EH),taller=FALSE告知根结点未因插入新结点而高度发生改变;
  2. 若根结点原本等高(EH),则因新结点的插入而使根结点左高(LH),taller=TRUE告知根结点因插入新结点高度增高;
  3. 若根结点原本左高(LH),向左插入新结点后,根结点失衡,故因左调平根结点。
    else if(LT(elem.number,(*T)->data.number)) {//insert its left child treeif(!InsertAVLTree(&((*T)->lchild),taller,elem)) return ERROR;if(!*taller) return OK;switch((*T)->bf) { //update the BF of the nodecase LH://adjust to make it balancedL_Balance(T);*taller=FALSE; break;case EH: (*T)->bf=LH; *taller=TRUE; break;case RH: (*T)->bf=EH; *taller=FALSE; break;}//switch((*T)->bf)}

左调平根结点时,根据根结点左孩子的平衡因子,判断是LL型还是LR型,采用不同的调平方法。无论何种调平方法,都应遵循以下两原则:

  1. 确保二叉树性质不变,即中序遍历结果不变;
  2. 使最小失衡子树的高度降低。

若左孩子的平衡因子为左高(LH),说明为LL型,修改根结点和其左孩子的平衡因子EH,向左旋转根结点。若左孩子的平衡因子为右高(RH),说明为LR型,此时,根据其左孩子的右孩子的平衡因子,修改结点平衡因子再分三种情况进行讨论:

  1. 若其左的右孩子为左高(LH),则左和左的右孩子BF=EH,根结点BF=RH;
  2. 若其左的右孩子为等高(EH),则左孩子和根结点BF=EH。(左的右孩子已为EH);
  3. 若其左的右孩子为右高(RH),则根结点和左的右孩子BF=EH,左孩子BF=LH。
void LibManage::L_Balance(AVLTree *t){//adjust the root to make left tree balancedTNode *lc=(*t)->lchild,*rd;switch(lc->bf){ //check condition: LL or LR, through BF of root's lchildcase EH: //a case when deleting the node(*t)->bf=LH; lc->bf=RH;R_Rotate(t);break;case LH: //LL(*t)->bf=lc->bf=EH; //modify BFR_Rotate(t); //R rotate root nodebreak;case RH: //LRrd=lc->rchild;switch(rd->bf){ //modify BF according to different BF conditionscase LH: lc->bf=rd->bf=EH;  (*t)->bf=RH; break;case EH: lc->bf=(*t)->bf=EH; break;case RH: rd->bf=(*t)->bf=EH; lc->bf=LH; break;}//switch(rd->bf)L_Rotate(&((*t)->lchild)); //part Left rotation, firstlyR_Rotate(t); //root Right rotation, thenbreak;}//switch(lc->bf)
}

修正平衡因子后,对失衡子树进行旋转。先对失衡子树根结点的左孩子进行(局部)左旋转,再对根结点进行(整体)右旋。至此,结点左插调平完成。以下为左调平操作示意图解。

图解1

2.2 结点删除

AVL树结点的删除操作同二叉搜索树结点删除相同,但删除结点后需要调整使AVL树重新平衡。根据所删结点的双亲和孩子情况,分三种情况进行讨论:

  1. 若所删结点为叶子结点(无孩子),直接删除之。若其无双亲(即为AVL树的根结点),置AVL树根(root)为空(NULL);
  2. 若所删结点只有一孩子,令其双亲结点连接其孩子(至于是双亲的左还是右连接之,只需判断双亲和孩子的关键词大小,若双亲>孩子,则双亲左连之,反之,则双亲右连之)。若无双亲,可置树根(root)为所删结点的孩子;
  3. 若所删结点两孩子均存在,则可通过寻找其(在中序遍历下的)前驱或后继,来实现删除操作。为同程序一致,这里以寻找前驱为例。进入所删结点的左孩子,向其右方(通过遍历)寻至其最右方的结点(姑且称作待删结点的相邻点),将待删结点的值替换为相邻点的值。再进入待删结点的左子树中(递归),删除相邻点。
else if(EQ(bknum,(*curT)->data.number)) {//find the node, and delete itif(!((*curT)->lchild)) {//if(the node has no left child or has neither left nor right one)if(!preT) *curT=(*curT)->rchild;//if(the node has no parent)else if(LT(bknum,preT->data.number)) preT->lchild=(*curT)->rchild;//check the current node is its parent's left child or its right oneelse preT->rchild=(*curT)->rchild;*shorter=TRUE;}//if(!((*curT)->lchild))else if(!((*curT)->rchild)) {//if(the node has no right child but has left one)if(!preT) *curT=(*curT)->lchild;//if(the node has no parent)else if(LT(bknum,preT->data.number)) preT->lchild=(*curT)->lchild;//check the current node is its parent's left child or its right oneelse preT->rchild=(*curT)->lchild;*shorter=TRUE;}//else if(!((*curT)->rchild))else {//if(the node has both right and left child)TNode *tempT=(*curT)->lchild; //enter curT's left childwhile(tempT->rchild) //find curNode's precursor in inorder traversetempT=tempT->rchild;BookCpy(&((*curT)->data),tempT->data); //assign the precursor's data to the node that needs to be deletedDeleteAVLTree(&((*curT)->lchild),NULL,shorter, tempT->data.number); //delete the precursor of the deleted elem in curT's left child

接下来,对删除结点后的调平工作进行解释,同样,以删除根结点左子树中的结点为例,右子树中删除操作类似,不做赘述。

若所删结点的关键词<根结点的关键词,则进入根结点左子树中进行删除操作。删除后,向根结点回溯时,返回一个shorter,告知根结点因删除结点而高度是否发生改变。此时分三种情况进行讨论:

  1. 根结点原本左高(LH),删除后,根结点等高(EH),shorter=TRUE;
  2. 根结点原本等高(EH),删除后,根结点右高(RH),shorter=FALSE;
  3. 根结点原本右高(RH),删除后,根结点失衡,应当对其进行右调平R_Balance()操作。

调平前,需根据根结点的右孩子的平衡因子,判断调平后,失衡子树shorter情况如何,此时分三种情况进行讨论:

  1. 根的右孩子BF=LH,调平后,shorter=TRUE;
  2. 根的右孩子BF=EH,调平后,shorter=FALSE;
  3. 根的右孩子BF=RH,调平后,shorter=TRUE。(也可与情况1归并)
else if(LT(bknum,(*curT)->data.number)) {//if the keynum is less than the curT's numberif(!DeleteAVLTree(&((*curT)->lchild),*curT,shorter,bknum)) return ERROR;if(!*shorter) return OK;switch((*curT)->bf) {case LH: (*curT)->bf=EH; *shorter=TRUE; break;case EH: (*curT)->bf=RH; *shorter=FALSE; break;case RH://another 3 conditions need to be considered, according to curT's right child BFswitch((*curT)->rchild->bf) {case LH: *shorter=TRUE; break;case EH: *shorter=FALSE; break;case RH: *shorter=TRUE; break;}//switch((*curT)->rchild->bf)R_Balance(curT);}//switch((*curT)->bf)}//else if(LT(bknum,(*curT)->data.number))

判断回溯的shorter的结果后,开始右调平。右调平操作与结点插入时的右调平基本无异,但需在“通过根结点右孩子BF值判断是RR型还是RL型失衡”时,增加一种EH的情况。因为在插入时,只考虑了因插入才会产生的LH和RH情况,未将删除时所会遇到的EH纳入其中。当BF=EH时,先更新各结点的平衡因子,根结点的BF=RH,根结点右孩子的BF=LH,再根结点左旋。(同理,左平衡操作时,也需补充“EH条件”)。

void LibManage::R_Balance(AVLTree *t){//adjust the root to make right tree balancedTNode *rc=(*t)->rchild,*ld;switch(rc->bf){ //check condition: RL or RR, through BF of root's rchildcase EH: //a case when deleting the node(*t)->bf=RH; rc->bf=LH;L_Rotate(t);break;//......

以下为右调平操作图解。

图解2

3 测试结果

//为模拟方便起见,添加初始图书、阅读者和阅读者的借阅数据
//book={number,name,author,stock,total}
Book book1={“01”,“PromisedLand”,“Obama”,6,8};
Book book2={“02”,“Humans”,“Stanton”,4,5};
Book book3={“03”,“Becoming”,“Michelle”,0,3};
Book book4={“04”,“DeepEnd”,“Kinney”,0,6};
InsertAVLTree(&tree,&taller,book1);
InsertAVLTree(&tree,&taller,book2);
InsertAVLTree(&tree,&taller,book3);
InsertAVLTree(&tree,&taller,book4);
//reader={code,name,telephone,firstarc}
Reader reader1={1,“Sylvan”,“95566”,NULL};
Reader reader2={2,“JIXIANG”,“10086”,NULL};
AddReader(reader_list,reader1);
AddReader(reader_list,reader2);
//reader={booknumber,bookname,return date,*next}
ArcBox arcbox1={“01”,“PromisedLand”,20251211,NULL};
ArcBox arcbox2={“02”,“Humans”,20300201,NULL};
AddReaderBook(reader_list.readers[0],arcbox1);
AddReaderBook(reader_list.readers[0],arcbox2);
AddReaderBook(reader_list.readers[1],arcbox1);

(以下内容均来自终端)
//启动图书管理系统,设置系统时间
Launch Library Management System Successfully!
Set current time:20201120 successfully!

//菜单界面,待用户输入指令
* * * MENU * * *
(1). Add books
(2). Lend books
(3). Return books
(4). Erase books
(5). Print All Books
(6). Print All Readers
(7). *(Testing MODE)
(0). [ E X I T ]
* * * * * * * * *
Menu->Option:
//功能一、采编入库
Menu->Option: 1
- - - - Add Book - - - -
Book Number: ISBN 01
Increment: 2
Find the BOOK...
Would you like to increase it? (y/n)...
y
Original stock: 6 
Original total amount: 8 
- - - - Book Info - - - -
Name: PromisedLand
Author: Obama
Number: ISBN 01
Total: 10
Stock: 8
- - - - - - - - - - - - -
Increase successfully! 
Menu->Option: 1
- - - - Add Book - - - -
Book Number: ISBN 05
Increment: 3
ERROR: Can't find BOOK: ISBN 05 Would you like to create a new item? (y/n)...
y
Number: ISBN 05
Stock/Total: 3
Name: Sherlock
Author: Arthur
- - - - Book Info - - - -
Name: Sherlock
Author: Arthur
Number: ISBN 05
Total: 3
Stock: 3
- - - - - - - - - - - - -
Add new book successfully!  
//功能二、借阅
Menu->Option: 2
- - - - Lend Book - - - -
Reader Code: 01
- - - - Reader Info - - - -
Name: Sylvan
Code: 00001
Tele: 95566
Borrowed books: 
<Humans> | ISBN 02 |  Deadline:20300201([Normal])
<PromisedLand> | ISBN 01 |  Deadline:20251211([Normal])
- - - - - - - - - - - - -
Book Number to lend: ISBN 02
No borrow permission: The reader has borrowed a same book <Humans>.
//……相同操作省略
Book Number to lend: ISBN 03
ERROR: Book Stock of <Becoming> is not enough...
Menu->Option: 2
- - - - Lend Book - - - -
Reader Code: 02
- - - - Reader Info - - - -
Name: JIXIANG
Code: 00002
Tele: 10086
Borrowed books: 
<PromisedLand> | ISBN 01 |  Deadline:20251211([Normal])
- - - - - - - - - - - - -
Book Number to lend: ISBN 02
Return Date(e.g.20201230): 20191230
Lend Book Successfully!
Menu->Option: 2
- - - - Lend Book - - - -
Reader Code: 02
- - - - Reader Info - - - -
Name: JIXIANG
Code: 00002
Tele: 10086
Borrowed books: 
<Humans> | ISBN 02 |  Deadline:20191230(![Overdue]!)
<PromisedLand> | ISBN 01 |  Deadline:20251211([Normal])
- - - - - - - - - - - - -
No borrow permission: The reader has a book <Humans> needs to be returned before 20191230
Menu->Option: 2
- - - - Lend Book - - - -
Reader Code: 05
ERROR: Can't find reader 00005...
Would you like to create one? (y/n)...
y
Code: 00005 
Name: Benedict
Tele: 197362
- - - - Reader Info - - - -
Name: Benedict
Code: 00005
Tele: 197362
Borrowed books: (Empty) 
- - - - - - - - - - - - -
Add reader successfully! 
Book Number to lend: ISBN 01
Return Date(e.g.20201230): 20201231
Lend Book Successfully!
//功能三、还书
Menu->Option: 3
- - - - Return Book - - - -
Reader Code: 01
- - - - Reader Info - - - -
Name: Sylvan
Code: 00001
Tele: 95566
Borrowed books: 
<Humans> | ISBN 02 |  Deadline:20300201([Normal])
<PromisedLand> | ISBN 01 |  Deadline:20251211([Normal])
- - - - - - - - - - - - -
Book Number to return: ISBN 02
Return Successfully!
Menu->Option: 3
- - - - Return Book - - - -
Reader Code: 01
- - - - Reader Info - - - -
Name: Sylvan
Code: 00001
Tele: 95566
Borrowed books: 
<PromisedLand> | ISBN 01 |  Deadline:20251211([Normal])
- - - - - - - - - - - - -
Book Number to return: ISBN 01
Warning: Reader Sylvan has returned all books, now erase his or her info from the memory... 
Erased successfully! 
Return Successfully! 
Menu->Option: 6
- - - - Reader Info - - - -
Name: JIXIANG
Code: 00002
Tele: 10086
Borrowed books: 
<PromisedLand> | ISBN 01 |  Deadline:20251211([Normal])
- - - - - - - - - - - - -
//功能四、清除库存
Menu->Option: 4
- - - - Erase Book - - - -
Book Number to erase: ISBN 01
Delete book successfully! 
Menu->Option: 5
- - - - Book Info - - - -
Name: Becoming
Author: Michelle
Number: ISBN 03
Total: 3
Stock: 0
- - - - Book Info - - - -
Name: Humans
Author: Stanton
Number: ISBN 02
Total: 5
Stock: 4
- - - - Book Info - - - -
Name: DeepEnd
Author: Kinney
Number: ISBN 04
Total: 6
Stock: 0
- - - - - - - - - - - - -
//功能五、展示所有图书
//功能六、展示所有借阅者
//功能七、测试模式:便捷地测试AVL树的插入与删除。

4 总结分析

4.1 调试过程中的问题是如何解决的,以及对设计与实现的回顾讨论和分析

平衡二叉排序树(Balanced Binary Sort Tree),又称AVL树,是一种时间复杂度较低的理想的动态查找表。通过在树结点TNode中,增设整型变量bf(即平衡因子balance factor),来判定结点是否平衡。Bf为该结点左子树高与右子树高的差值,当其绝对值超过1以后,结点失衡,需要对其进行调平操作。

写程序过程中,遇到逻辑问题后,通过一步步debug,发现问题,解决问题。

4.2 算法的时间和空间复杂度的分析,以及进一步改进的设想

经分析,平衡二叉树的查找、插入和删除其时间复杂度均为1

◯(log⁡n).\bigcirc \left ( \log n\right ). (logn).

是一种理想的动态查找表。

4.3 本次实验的经验和体会

通过使用C语言编写平衡二叉树插入和删除部分,大量使用指针变量,深入理解了指针的含义和用法。函数中,重复使用回溯的方法进行二叉树平衡,加强了对算法逻辑对掌握。

使用C++编写图书管理部分,学习和培养了考虑项目要全面的能力。

语法错误越来越少,而真正困难的逻辑部分问题增多。

在编写平衡二叉树插入和删除时,调试过程中遇到许多问题,如旋转错误、结点平衡因子错误等等。Edsger W. Dijkstra曾说过,

“有效的程序员不应该浪费很多时间用于程序调试,他们应该一开始就不要把故障引入。” 2

表明,在写程序前就应当理清逻辑和考虑所有情况,因此,后续还需继续培养编程的逻辑性和严谨性。

5 完整代码(C++)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>/* status macro definition */
#define OK 1
#define ERROR 0
#define OVER_FLOW -2/* memory length macro definition */
#define MAXNAMELEN 15
#define MAXBOOKNUMBERLEN 20
#define MAXREADERNUM 20 //the max amount of all readers
#define MAXREADERCODEDIGIT 5 //max reader code digits
#define INDENTATION 0 //for printing the BiTree/* some macros related to AVLTree */
#define EQ(a,b) (!strcmp((a),(b)))
#define LT(a,b) (strcmp((a),(b))<0)
#define LH +1
#define EH 0
#define RH -1typedef int Status;
typedef enum {FALSE,TRUE} boolean;
typedef char *KeyType;
typedef char NameType[MAXNAMELEN];
typedef char *BookNum,BookNumType[MAXBOOKNUMBERLEN];
typedef char TeleType[11+1]; //telephone: 11digits
typedef unsigned int DateType; //return date
//typedef Book DataType; //data type in TNodetypedef struct{BookNumType number; //no prefix 'ISBN'NameType name;NameType author;int stock; //current amount of the bookint total; //total amount of the book
}Book,DataType;typedef struct TNode{DataType data;int bf; //balance factorstruct TNode *lchild,*rchild;
}TNode,*AVLTree;typedef struct ArcBox{BookNumType bknum;NameType bknam;DateType return_date; //e.g. 20010205struct ArcBox *next;
}ArcBox;typedef struct{int code;NameType name;TeleType tele; //telephoneArcBox *first_arc;
}Reader;typedef struct{Reader *readers;int length,size;
}AdjList;class LibManage{
public:AVLTree tree;AdjList reader_list;DateType current_date;LibManage();~LibManage() {DestoryTree(tree);}void Menu();void AddBook();void LendBook();void ReturnBook();void EraseBook();void OutputBooks();void OutputReaders();void TestMode();
private:void gettime();void PrintBook(Book b);void PrintBiTree_Simple(AVLTree T,int indent);void PrintBiTree_Detail(AVLTree T);void BookCpy(Book *a,Book b);void L_Rotate(AVLTree *t);void R_Rotate(AVLTree *t);void L_Balance(AVLTree *t);void R_Balance(AVLTree *t);TNode* SearchAVLTree(AVLTree T,BookNum bn);Status InsertAVLTree(AVLTree *T,boolean *taller,DataType elem);Status DeleteAVLTree(AVLTree *curT,AVLTree preT,boolean *shorter,KeyType bknum);Status InitAdjList(AdjList &list);Status AddReader(AdjList &list,const Reader &r);Status AddReaderBook(Reader &r,const ArcBox &ab);Status SearchReader(AdjList list,int code);Status DeleteReader(AdjList &list,int code);Status CheckBorrowPermission(Reader r,BookNum bknum=NULL);ArcBox* SearchBorrowedBook(Reader r,KeyType bknum,ArcBox* &prep);void ReaderCpy(Reader &r1,const Reader &r2);void PrintReader(const Reader &r);void PrintBorrowedBooks(Reader r);void DestoryTree(AVLTree &T);
};void LibManage::gettime(){//get system time and convert it to unsigned inttime_t rawtime;struct tm *ptminfo;time(&rawtime); //get time raw infoptminfo=localtime(&rawtime); //convert raw time info to processed and readable time infocurrent_date=((ptminfo->tm_year)+1900)*10000+(ptminfo->tm_mon)*100+(ptminfo->tm_mday);printf("Set current time:%u successfully! \n",current_date);
}LibManage::LibManage() {tree=NULL; //initialize treeInitAdjList(reader_list); //initialize AdjListprintf("Launch Library Management System Successfully! \n");gettime();/* Simulate a library, so add some items first *///book={number,name,author,stock,total}boolean taller=FALSE;Book book1={"01","PromisedLand","Obama",6,8};Book book2={"02","Humans","Stanton",4,5};Book book3={"03","Becoming","Michelle",0,3};Book book4={"04","DeepEnd","Kinney",0,6};InsertAVLTree(&tree,&taller,book1);InsertAVLTree(&tree,&taller,book2);InsertAVLTree(&tree,&taller,book3);InsertAVLTree(&tree,&taller,book4);//reader={code,name,telephone,firstarc}Reader reader1={1,"Sylvan","95566",NULL};Reader reader2={2,"JIXIANG","10086",NULL};AddReader(reader_list,reader1);AddReader(reader_list,reader2);//reader={booknumber,bookname,return date,*next}ArcBox arcbox1={"01","PromisedLand",20251211,NULL};ArcBox arcbox2={"02","Humans",20300201,NULL};AddReaderBook(reader_list.readers[0],arcbox1);AddReaderBook(reader_list.readers[0],arcbox2);AddReaderBook(reader_list.readers[1],arcbox1);
}void LibManage::DestoryTree(AVLTree &T){//free the memory of the tree, using post-order traverse to guarantee that the node's parent won't get lostif(!T) return;DestoryTree(T->lchild);DestoryTree(T->rchild);free(T); T=NULL;
}//the following function is related to AVLTreevoid LibManage::L_Rotate(AVLTree *t){//left rotate root node, and update the rootTNode *rc=(*t)->rchild;(*t)->rchild=rc->lchild;rc->lchild=*t;(*t)=rc;
}
void LibManage::R_Rotate(AVLTree *t){//right rotate root node, and update the rootTNode *lc=(*t)->lchild;(*t)->lchild=lc->rchild;lc->rchild=*t;(*t)=lc;
}
void LibManage::L_Balance(AVLTree *t){//adjust the root to make left tree balancedTNode *lc=(*t)->lchild,*rd;switch(lc->bf){ //check condition: LL or LR, through BF of root's lchildcase EH: //a case when deleting the node(*t)->bf=LH; lc->bf=RH;R_Rotate(t);break;case LH: //LL(*t)->bf=lc->bf=EH; //modify BFR_Rotate(t); //R rotate root nodebreak;case RH: //LRrd=lc->rchild;switch(rd->bf){ //modify BF according to different BF conditionscase LH: lc->bf=rd->bf=EH;  (*t)->bf=RH; break;case EH: lc->bf=(*t)->bf=EH; break;case RH: rd->bf=(*t)->bf=EH; lc->bf=LH; break;}//switch(rd->bf)L_Rotate(&((*t)->lchild)); //part Left rotation, firstlyR_Rotate(t); //root Right rotation, thenbreak;}//switch(lc->bf)
}
void LibManage::R_Balance(AVLTree *t){//adjust the root to make right tree balancedTNode *rc=(*t)->rchild,*ld;switch(rc->bf){ //check condition: RL or RR, through BF of root's rchildcase EH: //a case when deleting the node(*t)->bf=RH; rc->bf=LH;L_Rotate(t);break;case RH: //RR(*t)->bf=rc->bf=EH; //modify BFL_Rotate(t); //L rotate root nodebreak;case LH: //RLld=rc->lchild;switch(ld->bf){ //modify BF according to different BF conditionscase LH: (*t)->bf=rc->bf=EH; ld->bf=RH; break;case EH: rc->bf=(*t)->bf=EH; break;case RH: ld->bf=rc->bf=EH; (*t)->bf=LH; break;}//switch(rd->bf)R_Rotate(&((*t)->rchild)); //part Right rotation, firstlyL_Rotate(t); //root Left rotation, thenbreak;}//switch(lc->bf)
}TNode* LibManage::SearchAVLTree(AVLTree T,BookNum bn){/* if the booknum can be found in AVLTree, then return its address, else return NULL */if(!T) return NULL;if(EQ(bn,T->data.number)) return T;if(LT(bn,T->data.number)) return SearchAVLTree(T->lchild,bn);return SearchAVLTree(T->rchild,bn);
}Status LibManage::InsertAVLTree(AVLTree *T,boolean *taller,DataType elem){/* insert an elem to AVLTree, and adjust the tree to keep its balance. If elem has existed, then return ERROR, else return OK *//* parameter 'taller' means that after inserting the elem, the tree is taller or not. */if(!*T) { //create a new node*T=(TNode*)malloc(sizeof(TNode));if(!*T) exit(OVER_FLOW);BookCpy(&((*T)->data),elem);(*T)->bf=EH;(*T)->lchild=(*T)->rchild=NULL;*taller=TRUE;}else if(EQ(elem.number,(*T)->data.number)) {//if the node has already existedPrintBook((*T)->data);printf("ERROR: book <%s> has already been in the AVL Tree. \n",elem.name);*taller=FALSE;return ERROR;}else if(LT(elem.number,(*T)->data.number)) {//insert its left child treeif(!InsertAVLTree(&((*T)->lchild),taller,elem)) return ERROR;if(!*taller) return OK;switch((*T)->bf) { //update the BF of the nodecase LH://adjust to make it balancedL_Balance(T);*taller=FALSE; break;case EH: (*T)->bf=LH; *taller=TRUE; break;case RH: (*T)->bf=EH; *taller=FALSE; break;}//switch((*T)->bf)}else {//insert its right child treeif(!InsertAVLTree(&((*T)->rchild),taller,elem)) return ERROR;if(!*taller) return OK;switch((*T)->bf) { //update the BF of the nodecase LH: (*T)->bf=EH; *taller=FALSE; break;case EH: (*T)->bf=RH; *taller=TRUE; break;case RH://adjust to make it balancedR_Balance(T);*taller=FALSE; break;}//switch((*T)->bf)}return OK;
}Status LibManage::DeleteAVLTree(AVLTree *curT,AVLTree preT,boolean *shorter,KeyType bknum){/* delete a node in AVLTree according to its book number, and adjust the tree to keep its balance. If elem has existed, then return OK, else return ERROR *///©SylvanDing/* parameter 'shorter' means that after deleting the node, the tree is shorter or not. */if(!*curT) {//if the node doesn't existprintf("ERROR: Can't find BOOK: ISBN %s \n",bknum);*shorter=FALSE;return ERROR;}//if(!*curT)else if(EQ(bknum,(*curT)->data.number)) {//find the node, and delete itif(!((*curT)->lchild)) {//if(the node has no left child or has neither left nor right one)if(!preT) *curT=(*curT)->rchild;//if(the node has no parent)else if(LT(bknum,preT->data.number)) preT->lchild=(*curT)->rchild;//check the current node is its parent's left child or its right oneelse preT->rchild=(*curT)->rchild;*shorter=TRUE;}//if(!((*curT)->lchild))else if(!((*curT)->rchild)) {//if(the node has no right child but has left one)if(!preT) *curT=(*curT)->lchild;//if(the node has no parent)else if(LT(bknum,preT->data.number)) preT->lchild=(*curT)->lchild;//check the current node is its parent's left child or its right oneelse preT->rchild=(*curT)->lchild;*shorter=TRUE;}//else if(!((*curT)->rchild))else {//if(the node has both right and left child)TNode *tempT=(*curT)->lchild; //enter curT's left childwhile(tempT->rchild) //find curNode's precursor in inorder traversetempT=tempT->rchild;BookCpy(&((*curT)->data),tempT->data); //assign the precursor's data to the node that needs to be deletedDeleteAVLTree(&((*curT)->lchild),NULL,shorter, tempT->data.number); //delete the precursor of the deleted elem in curT's left childif(!*shorter) return OK;switch((*curT)->bf) {case LH: (*curT)->bf=EH; *shorter=TRUE; break;case EH: (*curT)->bf=RH; *shorter=FALSE; break;case RH://another 3 conditions need to be considered, according to curT's right child BFswitch((*curT)->rchild->bf) {case LH: *shorter=TRUE; break;case EH: *shorter=FALSE; break;case RH: *shorter=TRUE; break;}//switch((*curT)->rchild->bf)R_Balance(curT);}//switch((*curT)->bf)}}//else if(EQ(bknum,(*curT)->data.number))else if(LT(bknum,(*curT)->data.number)) {//if the keynum is less than the curT's numberif(!DeleteAVLTree(&((*curT)->lchild),*curT,shorter,bknum)) return ERROR;if(!*shorter) return OK;switch((*curT)->bf) {case LH: (*curT)->bf=EH; *shorter=TRUE; break;case EH: (*curT)->bf=RH; *shorter=FALSE; break;case RH://another 3 conditions need to be considered, according to curT's right child BFswitch((*curT)->rchild->bf) {case LH: *shorter=TRUE; break;case EH: *shorter=FALSE; break;case RH: *shorter=TRUE; break;}//switch((*curT)->rchild->bf)R_Balance(curT);}//switch((*curT)->bf)}//else if(LT(bknum,(*curT)->data.number))else {//if the keynum is larger than the curT's number, enter its right childif(!DeleteAVLTree(&((*curT)->rchild),*curT,shorter,bknum)) return ERROR;if(!*shorter) return OK;switch((*curT)->bf) {case LH://another 3 conditions need to be considered, according to curT's left child BFswitch((*curT)->lchild->bf) {case LH: *shorter=TRUE; break;case EH: *shorter=FALSE; break;case RH: *shorter=TRUE; break;}//switch((*curT)->rchild->bf)L_Balance(curT);case EH: (*curT)->bf=LH; *shorter=FALSE; break;case RH: (*curT)->bf=EH; *shorter=TRUE; break;}//switch((*curT)->bf)}//elsereturn OK;
}void LibManage::TestMode(){//this mode is for testing AVLTree's insertion and deletion quickly and easilyBook bk={"","","",0,0};AVLTree testT=NULL; boolean flag;printf("- - - Testing Mode - - -\n");printf("//This mode allows you to test AVLTree's insertion and deletion quickly and easily. Whenever you insert or delete an item, it will print the AVLTree: KeyValue(BalanceFactor) \n//Have created a new Empty AVLTree for testing... \n//Input numbers(like 01,21,36...) to insert it, input 'end' to stop inserting. \n");//©SylvanDingdo{flag=FALSE;scanf("%s",bk.number);getchar();if(EQ(bk.number,"end")) break;InsertAVLTree(&testT,&flag,bk);printf("* Tree Print * \n");PrintBiTree_Simple(testT,INDENTATION);}while(1);printf("//End inserting, and then you can input the item you wanna delete, input 'quit' to exit testing mode... \n");do{flag=FALSE;scanf("%s",bk.number);getchar();if(EQ(bk.number,"quit")) break;DeleteAVLTree(&testT,NULL,&flag,bk.number);printf("* Tree Print * \n");PrintBiTree_Simple(testT,INDENTATION);}while(1);printf("//Exit TESTING MODE... \n");
}//the following function is about Library Managementvoid LibManage::Menu(){printf("* * * MENU * * *\n");printf("(1). Add books\n");printf("(2). Lend books\n");printf("(3). Return books\n");printf("(4). Erase books\n");printf("(5). Print All Books\n");printf("(6). Print All Readers\n");printf("(7). *(Testing MODE)\n");printf("(0). [ E X I T ]\n");printf("* * * * * * * * *\n");
}void LibManage::BookCpy(Book *a,Book b){//copy b's info and assign it to astrcpy(a->number,b.number);strcpy(a->name,b.name);strcpy(a->author,b.author);a->stock=b.stock;a->total=b.total;
}void LibManage::PrintBook(Book b){printf("- - - - Book Info - - - -\n");printf("Name: %s\n",b.name);printf("Author: %s\n",b.author);printf("Number: ISBN %s\n",b.number);printf("Total: %d\n",b.total);printf("Stock: %d\n",b.stock);printf("- - - - - - - - - - - - -\n");
}void LibManage::PrintBiTree_Simple(AVLTree T,int indent){if(!T) return;printf("%*s%s(%d)\n",indent,"",T->data.number,T->bf);PrintBiTree_Simple(T->lchild,indent+1);PrintBiTree_Simple(T->rchild,indent+1);
}void LibManage::PrintBiTree_Detail(AVLTree T){if(!T) return;PrintBook(T->data);PrintBiTree_Detail(T->lchild);PrintBiTree_Detail(T->rchild);
}void LibManage::AddBook(){//to add a new book when bknum-related book doesn't exist in AVLTree, or increase its original amountAVLTree *T=&tree;TNode *node=NULL; char flag;BookNumType bknum; int amount;printf("- - - - Add Book - - - -\n");printf("Book Number: ISBN ");scanf("%s",bknum);printf("Increment: ");scanf("%d",&amount);getchar();if(!(node=SearchAVLTree(*T,bknum))) {boolean taller=FALSE;Book new_book; NameType bk_name,aut_name;printf("ERROR: Can't find BOOK: ISBN %s \n Would you like to create a new item? (y/n)...\n",bknum);scanf("%c",&flag);switch(flag){case 'n':case 'N': return; break;case 'y':case 'Y':printf("Number: ISBN %s\n",bknum);printf("Stock/Total: %d\n",amount);printf("Name: ");scanf("%s",bk_name);printf("Author: ");scanf("%s",aut_name);strcpy(new_book.number,bknum);strcpy(new_book.name,bk_name);strcpy(new_book.author,aut_name);new_book.stock=new_book.total=amount;if(!InsertAVLTree(T,&taller,new_book)) return;PrintBook(new_book);printf("Add new book successfully!  \n");break;default: printf("Error: Wrong command, try again...\n");}//switch(flag)}//if(!(node=SearchAVLTree(*T,bknum)))else {printf("Find the BOOK...\nWould you like to increase it? (y/n)...\n");scanf("%c",&flag);switch(flag){case 'n':case 'N': return; break;case 'y':case 'Y':printf("Original stock: %d \nOriginal total amount: %d \n",node->data.stock,node->data.total);node->data.stock+=amount;node->data.total+=amount;PrintBook(node->data);printf("Increase successfully! \n");break;default: printf("Error: Wrong command, try again...\n");}//switch(flag)}//else
}void LibManage::
LendBook(){//to lend booksint code,index; char flag;printf("- - - - Lend Book - - - -\n");printf("Reader Code: ");scanf("%d",&code);getchar();if((index=SearchReader(reader_list,code))<0) {index=reader_list.length;Reader newreader; newreader.first_arc=NULL;printf("ERROR: Can't find reader %0*d...\nWould you like to create one? (y/n)...\n",MAXREADERCODEDIGIT,code);scanf("%c",&flag);switch(flag){case 'n':case 'N': return; break;case 'y':case 'Y':printf("Code: %0*d \n",MAXREADERCODEDIGIT,code);newreader.code=code;printf("Name: ");scanf("%s",newreader.name);printf("Tele: ");scanf("%s",newreader.tele);if(!AddReader(reader_list,newreader)) return;PrintReader(reader_list.readers[reader_list.length-1]);printf("Add reader successfully! \n");break;default: printf("Error: Wrong command, try again...\n"); return;}//switch(flag)}//if(index<0)else {PrintReader(reader_list.readers[index]);if(!CheckBorrowPermission(reader_list.readers[index])) return;}//if(index>=0)BookNumType bknum; TNode *tptr;printf("Book Number to lend: ISBN ");scanf("%s",bknum);if(!CheckBorrowPermission(reader_list.readers[index],bknum)) return;if(!(tptr=SearchAVLTree(tree,bknum)))printf("ERROR: Can't find book: %s in Library System... \n",bknum);else if(tptr->data.stock<=0)printf("ERROR: Book Stock of <%s> is not enough... \n",tptr->data.name);else {ArcBox *new_arcbox=(ArcBox*)malloc(sizeof(ArcBox));if(!new_arcbox) exit(OVER_FLOW);--tptr->data.stock;printf("Return Date(e.g.20201230): ");scanf("%u",&(new_arcbox->return_date));strcpy(new_arcbox->bknum,bknum);strcpy(new_arcbox->bknam,tptr->data.name);new_arcbox->next=reader_list.readers[index].first_arc;reader_list.readers[index].first_arc=new_arcbox;printf("Lend Book Successfully! \n");}
}void LibManage::ReturnBook(){//to return booksint code,index; TNode *tptr;BookNumType bknum; ArcBox *abptr,*pre_abptr;printf("- - - - Return Book - - - -\n");printf("Reader Code: ");scanf("%d",&code);getchar();if((index=SearchReader(reader_list,code))<0) {printf("ERROR: Can't find reader %0*d...\n",MAXREADERCODEDIGIT,code);return;}PrintReader(reader_list.readers[index]);printf("Book Number to return: ISBN ");scanf("%s",bknum);if(!(abptr=SearchBorrowedBook(reader_list.readers[index],bknum,pre_abptr))) {printf("ERROR: No lended book: %s...\n",bknum);return;}if(!pre_abptr)reader_list.readers[index].first_arc=abptr->next;elsepre_abptr->next=abptr->next;free(abptr);if(!reader_list.readers[index].first_arc) {printf("Warning: Reader %s has returned all books, now erase his or her info from the memory... \n",reader_list.readers[index].name);DeleteReader(reader_list,index);printf("Erased successfully! \n");}if((tptr=SearchAVLTree(tree,bknum)))++tptr->data.stock;printf("Return Successfully! \n");
}void LibManage::EraseBook(){//to erase bookBookNumType bknum; boolean shorter;printf("- - - - Erase Book - - - -\n");printf("Book Number to erase: ISBN ");scanf("%s",bknum);getchar();if(DeleteAVLTree(&tree,NULL,&shorter,bknum))printf("Delete book successfully! \n");
}void LibManage::OutputBooks(){//in-order traverse the AVLTreeif(!tree){printf("No book... \n");return;}PrintBiTree_Detail(tree);
}void LibManage::OutputReaders(){if(reader_list.length<=0) {printf("No reader... \n");return;}for(int i=0;i<reader_list.length;++i)PrintReader(reader_list.readers[i]);
}//the following function is about Readers ManagementStatus LibManage::InitAdjList(AdjList &list){//initialize reader adjacency listif(!(list.readers=(Reader*)malloc(MAXREADERNUM*sizeof(Reader)))) exit(OVER_FLOW);list.length=0; list.size=MAXREADERNUM;return OK;
}Status LibManage::AddReader(AdjList &list, const Reader &newr){//add a new reader to reader listif(list.length>=list.size) {printf("ERROR: System unable to hold more readers... \n");return ERROR;}ReaderCpy(list.readers[list.length++],newr);return OK;
}Status LibManage::AddReaderBook(Reader &r,const ArcBox &ab){//for stimulating a whole library management//no real functionArcBox *abptr=(ArcBox*)malloc(sizeof(ArcBox));if(!abptr) exit(OVER_FLOW);strcpy(abptr->bknum,ab.bknum);strcpy(abptr->bknam,ab.bknam);abptr->return_date=ab.return_date;abptr->next=r.first_arc;r.first_arc=abptr;return OK;
}Status LibManage::SearchReader(AdjList list,int code){//if 'code' exists, then return its index, else return -1int index=0;while(index<list.length&&code!=list.readers[index].code) ++index;if(index<list.length) return index;else return -1;
}Status LibManage::DeleteReader(AdjList &list,int index){while(index<list.length) {ReaderCpy(list.readers[index],list.readers[index+1]);++index;}--list.length;return OK;
}Status LibManage::CheckBorrowPermission(Reader r,BookNum bknum){//if the second parameter 'bknum'=NULL, only check whether the borrower has overdue unreturned book, if he does, return 0, else return 1//if the 'bknum'!=NULL, then check if there has any same book that he has already borrowed. if he does, return 0, else return 1ArcBox *p=r.first_arc;if(!bknum) {while(p&&p->return_date>=current_date)p=p->next;if(p) {printf("No borrow permission: The reader has a book <%s> needs to be returned before %u \n",p->bknam,p->return_date);return 0;}else return 1;}//if(!bknum)else {while(p&&!EQ(bknum,p->bknum))p=p->next;if(p) {printf("No borrow permission: The reader has borrowed a same book <%s>. \n",p->bknam);return 0;}else return 1;}//else
}ArcBox* LibManage::SearchBorrowedBook(Reader r,KeyType bknum,ArcBox* &prep){//if bknum can be found in reader's borrowed list, then return its arcbox's address, else return NULL.//prep return temp's precursor, when it has no precursor, return NULLArcBox *temp=r.first_arc; prep=NULL;while(temp&&!EQ(bknum,temp->bknum)){prep=temp;temp=temp->next;}return temp;
}void LibManage::ReaderCpy(Reader &r1,const Reader &r2){//copy reader's info from r2 to r1strcpy(r1.name,r2.name);strcpy(r1.tele,r2.tele);r1.code=r2.code;r1.first_arc=r2.first_arc;
}void LibManage::PrintReader(const Reader &r){printf("- - - - Reader Info - - - -\n");printf("Name: %s\n",r.name);printf("Code: %0*d\n",MAXREADERCODEDIGIT,r.code);printf("Tele: %s\n",r.tele);PrintBorrowedBooks(r);printf("- - - - - - - - - - - - -\n");
}void LibManage::PrintBorrowedBooks(Reader r){printf("Borrowed books: \n");if(!r.first_arc) printf("\t(Empty) \n");while(r.first_arc) {printf("<%s> | ISBN %s |  Deadline:%u(%s)\n",r.first_arc->bknam,r.first_arc->bknum,r.first_arc->return_date,current_date>r.first_arc->return_date? "![Overdue]!":"[Normal]");r.first_arc=r.first_arc->next;}
}int main(int argc, char *argv[]){LibManage LMSystem;int opt;LMSystem.Menu();do{printf("Menu->Option: ");scanf("%d",&opt);getchar();switch(opt){case 0: break;case 1: LMSystem.AddBook(); break;case 2: LMSystem.LendBook(); break;case 3: LMSystem.ReturnBook(); break;case 4: LMSystem.EraseBook(); break;case 5: LMSystem.OutputBooks(); break;case 6: LMSystem.OutputReaders(); break;case 7: LMSystem.TestMode(); break;default: printf("ERROR: Wrong command, try again... \n"); break;}//switch(opt)}while(opt);return 0;
}

头一次写文章难免有些纰漏,还望各位指正。


  1. 二叉搜索树,平衡二叉树,红黑树的算法效率 ↩︎

  2. 艾兹格·W·迪科斯彻 (Edsger Wybe Dijkstra,1930年5月11日~2002年8月6日) ↩︎

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

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

相关文章

物联网产业104页深度研究报告:物联网研究框架与投资机会分析

报告出品方&#xff1a;国信证券作者&#xff1a;马成龙、付晓钦、陈彤1物联网是未来五年甚至十年的大赛道1.1 物联网&#xff1a;下一代网络网络革命的本质是连接主体和连接方式的变化&#xff1a;第一代互联网&#xff08;PC互联网&#xff09;是计算机与计算机之间的联网&am…

随笔:朋友圈扫街图有感(爱情)

#声明&#xff1a;照片来自我的一位甘姓友人&#xff0c;并非本人所拍。但为之感动&#xff0c;尤其震撼。 皮夹里老照片上恰风华正茂的少年&#xff0c;但如今一双褶皱的手&#xff0c;缓缓掏出过了时的纸币&#xff0c;无疑岁月蹉跎&#xff0c;当年的Ta早已成了耄耋老人。说…

浅谈SDN架构下的运维工作

导读目前国内的网络运维还处于初级阶段&#xff0c;工作人员每天就像救火一样&#xff0c;天天疲于奔命。运维人员只能埋头查找系统运行的日志&#xff0c;耗时耗力&#xff0c;老眼昏花不说&#xff0c;有时候忙了半天还一无所获&#xff0c;作为运维工程师的你&#xff0c;有…

华为自动驾驶实车实路测试视频曝光!徐直军:比特斯拉好多了

资料来源&#xff1a;量子位、物联网智库等整理发布&#xff1a;物联网智库 昨日&#xff08;4月15日&#xff09;&#xff0c;消息称配备华为自动驾驶技术的北汽新能源极狐阿尔法S的HI版车型在上海进行了公开试乘&#xff0c;这也是华为自动驾驶技术公开试乘的全球首秀。以下视…

Pycharm社区版运行Django的三种方法(Pycharm添加配置参数快捷启动Django、Pycharm社区版Django项目创建)

目录Pycharm社区版运行Django的三种方法Django安装和环境变量的配置&#xff08;MacOS&#xff09;创建Project启动Django Webserver方法一&#xff1a;终端启动方法二&#xff1a;pycharm项目界面启动方法三&#xff1a;pycharm社区版实现直接启动Pycharm社区版运行Django的三…

日本机器人全球领先来自这三大顶尖技术

来源&#xff1a;工业机器人▍日本尖端技术之一&#xff1a;机器人精密减速机世界上工业机器人使用的精密减速机几乎都为日本所垄断。尽管国内也量产的RV减速机&#xff0c;但国产机器人企业却鲜有选用的&#xff0c;原因是日本精密减速机技术遥遥领先&#xff0c;短期很难替代…

仰望星空后,更将脚踏实地!

仰望星空后&#xff0c;更将脚踏实地&#xff01;

在目标检测中如何解决小目标的问题?

作者&#xff1a;Nabil MADALI来源&#xff1a;AI公园编译&#xff1a;ronghuaiyang在深度学习目标检测中&#xff0c;特别是人脸检测中&#xff0c;由于分辨率低、图像模糊、信息少、噪声多&#xff0c;小目标和小人脸的检测一直是一个实用和常见的难点问题。然而&#xff0c;…

python学习之路day02

一、.pyc是什么&#xff1f; 1. Python是一门解释型语言&#xff1f; 我初学Python时&#xff0c;听到的关于Python的第一句话就是&#xff0c;Python是一门解释性语言&#xff0c;我就这样一直相信下去&#xff0c;直到发现了*.pyc文件的存在。如果是解释型语言&#xff0c;那…

像人一样自然流畅地说话,下一代智能对话系统还有多长的路要走?

来源&#xff1a;机器之心机器之心编辑部作为人工智能的一个子领域&#xff0c;自然语言处理&#xff08;NLP&#xff09;指的是机器理解并解释人类书面语和口语的能力&#xff0c;目的在于使计算机像人类一样智能地理解语言和用语言表达&#xff0c;弥补人类交流&#xff08;自…

机器学习:简单的随机梯度下降(SGD)求解回归问题和用逻辑回归(LR)解决分类问题

20210405作业&#xff1a; 回归问题: 用随机梯度下降法实现&#xff0c;数据用data.csv。分类问题: 用梯度下降实现逻辑回归&#xff0c;可以用批量梯度也可以用随机梯度实现。数据采用西瓜数据3.0α.csv。 1. SGD (Stochastic gradient descent) # 导包 import numpy as np i…

Nature『大脑废物清除系统』已上线,从“痴呆”变聪明或成可能

来源&#xff1a;生物通 利用早发性阿尔茨海默氏症的小鼠模型&#xff0c;研究人员移除了一组小鼠大脑中的一些淋巴管。他们给这些小鼠以及对照组注射了单克隆抗体疗法&#xff0c;包括小鼠版本的Aducanumab。对小鼠大脑的研究显示&#xff0c;脑膜淋巴系统(紫色和粉红色)可以…

Unity3D_(API)Quaternion四元数中的Quaternion.LookRotation()

四元数百度百科&#xff1a;  传送门 四元数官方文档&#xff1a;  传送门 欧拉旋转、四元数、矩阵旋转之间的差异&#xff1a;  传送门 四元数转换为欧拉角eulerAngles  官方文档&#xff1a;  传送门 欧拉角转换为四元数Euler  官方文档&#xff1a;  传送门 Q…

思考:那么些大学生仅凭个人好恶来判断,缺乏是非观

“一切仅凭自己的好恶来判断&#xff0c;是缺乏是非观的体现” 今读某大学Z教授&#xff08;一位授课严谨认真的老师&#xff0c;在我心中&#xff0c;至少我是这样认为的&#xff09;的推文&#xff0c;深受触动。文章小中见大&#xff0c;批判了精致的利己主义思想&#xff0…

工业互联网的十大关键传感器

来源&#xff1a;传感器专家网工业互联网(Industrial Internet)是制造业一大热潮。从早期GE提出工业互联网理念被不少人解读为美国的制造业复兴战略&#xff0c;到GE的Predix平台受到热捧&#xff0c;再到西门子推出工业互联网平台Mindsphere&#xff0c;及多家本土的制造业巨头…

抽奖系统的流量削峰方案

如果观看抽奖或秒杀系统的请求监控曲线&#xff0c;你就会发现这类系统在活动开放的时间段内会出现一个波峰&#xff0c;而在活动未开放时&#xff0c;系统的请求量、机器负载一般都是比较平稳的。为了节省机器资源&#xff0c;我们不可能时时都提供最大化的资源能力来支持短时…

SVM支持向量机-手写笔记(超详细:拉格朗日乘数法、KKT条件、对偶性质、最优化、合页损失、核函数...)

SVM支持向量机-手写笔记 作者&#xff1a;某丁 日期&#xff1a;2021.05.21 写完了&#xff0c;发现想要真正理解SVM还需要继续深入学习&#xff0c;以上所写只不过是冰山一角&#xff0c;我的管中窥豹而已。 参考 [1] 一文搞懂支持向量机(SVM)算法 https://zhuanlan.zhihu.co…

扛鼎之作!Twitter 图机器学习大牛发表160页论文:以几何学视角统一深度学习

来源&#xff1a;AI科技评论作者&#xff1a;Michael Bronstein编译&#xff1a;Mr Bear、青暮导语&#xff1a;近日&#xff0c;帝国理工学院教授、Twitter 首席科学家 Michael Bronstein 发表了一篇长达160页的论文&#xff08;或者说书籍&#xff09;&#xff0c;试图从对称…

情感数据对LSTM股票预测模型的影响研究

情感数据对LSTM股票预测模型的影响研究 作者&#xff1a;丁纪翔 发布时间&#xff1a;06/28/2021 摘要&#xff1a;探究了情感结构化特征数据在LSTM股票预测模型中的影响。利用Pandas对所给数据进行预处理&#xff08;数据载入、清洗与准备、规整、时间序列处理、数据聚合等&am…

AI芯片发展现状及前景分析

来源&#xff1a;专知1. AI芯片定义及技术架构1.1 AI芯片定义广义上所有面向AI应用的芯片都可以称为AI芯片。目前一般认为是针对AI算法做了特殊加速设计的芯片。现阶段&#xff0c;这些人工智能算法一般以深度学习算法为主&#xff0c;也可以包括其他浅层机器学习算法[7-8]。1.…