人工智能实验王浩算法Word下载.docx
- 文档编号:22586674
- 上传时间:2023-02-04
- 格式:DOCX
- 页数:27
- 大小:49.94KB
人工智能实验王浩算法Word下载.docx
《人工智能实验王浩算法Word下载.docx》由会员分享,可在线阅读,更多相关《人工智能实验王浩算法Word下载.docx(27页珍藏版)》请在冰豆网上搜索。
structnode{
char*s;
typekind;
intpolar;
node*next;
node*child;
intstart;
structstep{
step*child;
step*brother;
node*lhead;
node*rhead;
intcount;
charname[30];
//初始化,输入表达式
intinite(char*s,node*head){
intlen=strlen(s);
intj=0,polar=1;
node*current=NULL;
node*last=NULL;
if(s==NULL)return0;
last=head;
while(i<
len){
if(s[i]=='
|'
){
if(!
(s[i+1]<
='
Z'
&
s[i+1]>
A'
||s[i+1]<
z'
a'
)&
s[i+1]!
1'
0'
('
!
'
||i==0)return0;
current=(node*)malloc(sizeof(node));
current->
kind=or;
s=NULL;
next=NULL;
child=NULL;
polar=polar;
start=0;
if(last->
kind==level&
last->
child==NULL){
last->
child=current;
}
else{
next=current;
last=current;
i++;
}
elseif(s[i]=='
current=(node*)malloc(sizeof(node));
current->
kind=and;
if(last->
last->
}
else{
last=current;
i++;
)return0;
polar=1-polar;
-'
if(s[i+1]!
>
||(s[i+2]!
s[i+2]!
(s[i+2]<
s[i+2]>
||s[i+2]<
))||i==0)return0;
kind=detrusion;
i=i+2;
<
if((s[i+1]!
||s[i+2]!
)||(s[i+3]!
s[i+3]!
(s[i+3]<
s[i+3]>
||s[i+3]<
)||i==0)&
kind=equal;
i=i+3;
elseif(s[i]<
s[i]>
||s[i]<
kind=variable;
s=(char*)malloc(MAX_L*sizeof(char));
j=0;
while((s[i]<
)||(s[i]<
9'
)){
(current->
s)[j]=s[i];
j++;
if(s[i]!
s[i]!
\0'
)'
(current->
s)[j]='
;
polar=1;
||s[i]=='
s=(char*)malloc(2*sizeof(char));
s)[0]=s[i];
s)[1]='
kind=level;
polar=1;
if(!
inite(s,last))return0;
P'
return1;
elsereturn0;
}
return1;
}
//复制函数
node*clone(node*parent){
node*son=NULL;
if(parent==NULL)returnNULL;
son=(node*)malloc(sizeof(node));
son->
kind=parent->
kind;
polar=parent->
polar;
s=parent->
s;
start=parent->
start;
if(parent->
next!
=NULL){
son->
next=clone(parent->
next);
else{
child!
child=clone(parent->
child);
returnson;
voidremove(node*head){
current=head;
if(current==NULL)return;
if(current->
current->
child->
kind==variable&
next==NULL){
current->
polar=(current->
polar==current->
polar);
polar=1;
while(current->
child=current->
child;
=NULL)remove(current->
voidrestruct(node*head){
node*newone=NULL,*newtwo=NULL,*newthree=NULL,*newfour=NULL,*newcurrent=NULL;
intorder=1;
while(order<
=4){
last=head;
current=last->
while(current!
if((current->
kind==variable||current->
kind==level)&
order==1){
if(current->
=NULL&
next->
kind==and){
newone=(node*)malloc(sizeof(node));
newone->
polar=0;
if(last->
kind==level){
last->
child=newone;
}
else{
next=newone;
next=current->
next;
current->
polar=1-current->
current=newone;
last=current;
current=current->
elseif((current->
order==2){
kind==or){
newone=(node*)malloc(sizeof(node));
order==3){
kind==equal){
newtwo=(node*)malloc(sizeof(node));
newtwo->
newthree=(node*)malloc(sizeof(node));
newthree->
newfour=(node*)malloc(sizeof(node));
newfour->
child=newtwo;
next=newthree;
next=newfour;
newcurrent=clone(current);
newcurrent->
child=newcurrent->
next=newcurrent->
next=newcurrent;
elseif(current->
order==4){
restruct(current);
current=current->
order++;
voidshow(node*head){
while(current!
if(current->
if(current->
polar==0)printf("
"
);
start!
=1||(current->
polar==0&
=NULL))printf("
("
show(current->
)"
current=current->
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 人工智能 实验 算法