广义表c语言实现
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}LLS;
int CmpC(char *str)
{
int i=0;
char k;
LLS *q;
LLS head1,head2,head3;
head1.next=head2.next=head3.next=NULL;
while((k=str[i]) !='\n')
{
if(k=='(')
{
q=(LLS *)malloc(sizeof(LLS));
Point_0-=1;
}
return 0;
}
int main(void)
{
int *tws;
int S=0;
int *data=(int *)malloc(sizeof(int));
inistak(tws);
while(1)
{
printf("Select:\n1.PUSH head\n2.POP head\n3.PUSH tail\n4.POP tail");
Ons=(int *)malloc((N+1)*sizeof(int));
for(i=0;i<=N;i++) *(Ons+i)=0;
for(i=0;i<N;i++)
{
push(train[i]);
printf("Train %d push\n",i+1);
if(Ons[Point]) {pop(temp+j);j++;printf("Train %d out\n",i+1);}
}
system("pause");
return 0;
}
#include<stdio.h>
typedef struct LLS{
int C;
struct LLS *next;
}LLS;
int Count(char *str)
{
int i=0;
LLS head;
LLS *q;
char k;
head.next=(LLS*)malloc(sizeof(LLS));
#include<stdio.h>
int Point_0=0;
int Point_1=11;
void inistak(int *tws)
{
int i=0;
while(!(tws=(int *)malloc((2*5+1)*sizeof(int))));
for(i=1;i<=10;i++) *(tws+i)=0;
printf("\n");
S=push(tws,1,data);
if(S) printf("Stack is full");
else printf("%d is Pushed",*data);
}
else if(S==4)
{
if(pop(tws,1,data)) printf("Stack is empty");
}
else if(S==2)
{
if(pop(tws,0,data)) printf("Stack is empty");
else printf("pop is %d",*data);
}
else if(S==3)
{
printf("Input data(int): ");
scanf("%d",data);
head.next=q;
}
while(1)
{
k=getchar();
if(k=='@' && !head.next) break;
else if(!head.next) return 0;
else if(k!=head.next->C) return 0;
head.next=head.next->next;
{
while(1)
{
if(CmpC()) printf("Not Matched!!\n");
else printf("Matched!!\n");
}
system("pause");
return 0;
}
#include<stdio.h>
typedef struct LLS{
char C;
struct LLS *next;
q->next=head2.next;
head2.next=q;
}
else if(k==']')
{
if(!head2.next) return 1;
else head2.next=head2.next->next;
}
else if(k=='{')
{
q=(LLS *)malloc(sizeof(LLS));
*(Ons+Point)=x;
return 0;
}
int pop(int *x)
{
if(Point)
{
*x=*(Ons+Point);
Point--;
return 0;
}
return 1;
}
void Arrange(int *ons,int *train,int *temp)
{
int i=0,j=0;
}
int push(int *tws,int i,int *x)/*i=0时正向,i=1时反向*/
{
int j;
if(i)
{
Point_1--;
j=Point_1;
if(j<=5) {++Point_1;return 1;}
}
else
{
Point_0++;
j=Point_0;
if(j>5) {--Point_0;return 1;}
printf("\n");
scanf("%d",&S);
if(S==1)
{
printf("Input data(int): ");
scanf("%d",data);
printf("\n");
S=push(tws,0,data);
if(S) printf("Stack is full");
else printf("%d is Pushed",*data);
q->next=head3.next;
head3.next=q;
}
else if(k=='}')
{
if(!head3.next) return 1;
else head3.next=head3.next->next;
}
i++;
}
if(head1.next || head2.next || head3.next) return 1;
case '/' : head.next->next->C=head.next->next->C /head.next->C;head.next->C=head.next->next->C;i++;break;
default : q=(LLS*)malloc(sizeof(LLS));
q->C=0;
while(k<'9' && k>'0')
{
q->C=q->C*10+(k-'0');
i++;
k=str[i];
}
i++;
q->next=head.next;
head.next=q;
}
k=str[i];
}
return head.next->C;
}
int main(void)
{
char str[100];
char C;
struct LLS *next;
}LLS;
int CmpS(void)
{
LLS head;
LLS *q;
char k;
head.next=NULL;
while((k=getchar())!= '&')
{
q=(LLS *)malloc(sizeof(LLS));
q->C=k;
q->next=head.next;
q->next=head1.next;
head1.next=q;
}
else if(k==')')
{
if(!head1.next) return 1;
else head1.next=head1.next->next;
}
else if(k=='[')
{
q=(LLS *)malloc(sizeof(LLS));
else if(m>0 && n>=0) return g(m-1,2*n)+n;
}
int main(void)
{
printf("g(5,2)=%d",g(5,2));
system("pause");
return 0;
}
#include<stdio.h>
int F1(int n)
{
if(n==0) return 1;
char C;
struct LLS{
LLS head;
LLS *q;
char k;
head.next=NULL;
while((k=getchar()) !='\n')
{
if(k=='(')
{
q=(LLS *)malloc(sizeof(LLS));
}
while(j<N)
{
pop(temp+j);
j++;
}
}
int main(void)
{
int i=0;
int train[10]={0,0,1,0,1,1,1,0,1,1};
int temp[10];
for(i=0;i<N;i++)
{
if(train[i]) printf("H ");
else printf("S ");
head.next->C=0;
k=str[i];
while(k!='\n')
{
switch(k)
{
case '+' : head.next->next->C=head.next->next->C + head.next->C;head.next->C=head.next->next->C;i++;break;
case '-' : head.next->next->C=head.next->next->C - head.next->C;head.next->C=head.next->next->C;i++;break;
case '*' : head.next->next->C=head.next->next->C * head.next->C;head.next->C=head.next->next->C;i++;break;
}
printf("\n");
Arrange(Ons,train,temp);
for(i=0;i<N;i++)
{
if(temp[i]) printf("H ");
else printf("S ");
}
system("pause");
return 0;
}
#include<stdio.h>
typedef struct LLS{
q->next=head.next;
head.next=q;
}
else if(k==')')
{
if(!head.next) return 1;
else head.next=head.next->next;
}
}
if(head.next) return 1;
else return 0;
}
int main(void)
else printf("pop is %d",*data);
}
system("pause");
}
return 0;
}
#include<stdio.h>
int * Ons=NULL;
int Point=0;
int N=10;
int push(int x)
{
Point++;
if(Point>N) return 1;
printf("Input :");
scanf("%s",str);
printf("\n");
printf("%s = %d\n",str,Count(str));
system("pause");
return 0;
}
#include<stdio.h>
int g(int m,int n)
{
if(m==0 && n>=0) return 0;
else if(n>0) return n*F1(n/2);
}
int F2(int n)
{
int sum=1;
if(n==0) return 1;
else if(n>0)
{
sum=n;
while(n/2!=0)
{
sum=sum*(n/2);
}
return 1;
}
int main()
{
while(1)
{
if(CmpS()) printf("Matched\n");
else printf("Not Matched!\n");
}
system("pause");
return 0;
}
#include<stdio.h>
typedef struct LLS{
else return 0;
int CmpC(char *str)
{
int i=0;
char k;
LLS *q;
LLS head1,head2,head3;
head1.next=head2.next=head3.next=NULL;
while((k=str[i]) !='\n')
{
if(k=='(')
{
q=(LLS *)malloc(sizeof(LLS));
Point_0-=1;
}
return 0;
}
int main(void)
{
int *tws;
int S=0;
int *data=(int *)malloc(sizeof(int));
inistak(tws);
while(1)
{
printf("Select:\n1.PUSH head\n2.POP head\n3.PUSH tail\n4.POP tail");
Ons=(int *)malloc((N+1)*sizeof(int));
for(i=0;i<=N;i++) *(Ons+i)=0;
for(i=0;i<N;i++)
{
push(train[i]);
printf("Train %d push\n",i+1);
if(Ons[Point]) {pop(temp+j);j++;printf("Train %d out\n",i+1);}
}
system("pause");
return 0;
}
#include<stdio.h>
typedef struct LLS{
int C;
struct LLS *next;
}LLS;
int Count(char *str)
{
int i=0;
LLS head;
LLS *q;
char k;
head.next=(LLS*)malloc(sizeof(LLS));
#include<stdio.h>
int Point_0=0;
int Point_1=11;
void inistak(int *tws)
{
int i=0;
while(!(tws=(int *)malloc((2*5+1)*sizeof(int))));
for(i=1;i<=10;i++) *(tws+i)=0;
printf("\n");
S=push(tws,1,data);
if(S) printf("Stack is full");
else printf("%d is Pushed",*data);
}
else if(S==4)
{
if(pop(tws,1,data)) printf("Stack is empty");
}
else if(S==2)
{
if(pop(tws,0,data)) printf("Stack is empty");
else printf("pop is %d",*data);
}
else if(S==3)
{
printf("Input data(int): ");
scanf("%d",data);
head.next=q;
}
while(1)
{
k=getchar();
if(k=='@' && !head.next) break;
else if(!head.next) return 0;
else if(k!=head.next->C) return 0;
head.next=head.next->next;
{
while(1)
{
if(CmpC()) printf("Not Matched!!\n");
else printf("Matched!!\n");
}
system("pause");
return 0;
}
#include<stdio.h>
typedef struct LLS{
char C;
struct LLS *next;
q->next=head2.next;
head2.next=q;
}
else if(k==']')
{
if(!head2.next) return 1;
else head2.next=head2.next->next;
}
else if(k=='{')
{
q=(LLS *)malloc(sizeof(LLS));
*(Ons+Point)=x;
return 0;
}
int pop(int *x)
{
if(Point)
{
*x=*(Ons+Point);
Point--;
return 0;
}
return 1;
}
void Arrange(int *ons,int *train,int *temp)
{
int i=0,j=0;
}
int push(int *tws,int i,int *x)/*i=0时正向,i=1时反向*/
{
int j;
if(i)
{
Point_1--;
j=Point_1;
if(j<=5) {++Point_1;return 1;}
}
else
{
Point_0++;
j=Point_0;
if(j>5) {--Point_0;return 1;}
printf("\n");
scanf("%d",&S);
if(S==1)
{
printf("Input data(int): ");
scanf("%d",data);
printf("\n");
S=push(tws,0,data);
if(S) printf("Stack is full");
else printf("%d is Pushed",*data);
q->next=head3.next;
head3.next=q;
}
else if(k=='}')
{
if(!head3.next) return 1;
else head3.next=head3.next->next;
}
i++;
}
if(head1.next || head2.next || head3.next) return 1;
case '/' : head.next->next->C=head.next->next->C /head.next->C;head.next->C=head.next->next->C;i++;break;
default : q=(LLS*)malloc(sizeof(LLS));
q->C=0;
while(k<'9' && k>'0')
{
q->C=q->C*10+(k-'0');
i++;
k=str[i];
}
i++;
q->next=head.next;
head.next=q;
}
k=str[i];
}
return head.next->C;
}
int main(void)
{
char str[100];
char C;
struct LLS *next;
}LLS;
int CmpS(void)
{
LLS head;
LLS *q;
char k;
head.next=NULL;
while((k=getchar())!= '&')
{
q=(LLS *)malloc(sizeof(LLS));
q->C=k;
q->next=head.next;
q->next=head1.next;
head1.next=q;
}
else if(k==')')
{
if(!head1.next) return 1;
else head1.next=head1.next->next;
}
else if(k=='[')
{
q=(LLS *)malloc(sizeof(LLS));
else if(m>0 && n>=0) return g(m-1,2*n)+n;
}
int main(void)
{
printf("g(5,2)=%d",g(5,2));
system("pause");
return 0;
}
#include<stdio.h>
int F1(int n)
{
if(n==0) return 1;
char C;
struct LLS{
LLS head;
LLS *q;
char k;
head.next=NULL;
while((k=getchar()) !='\n')
{
if(k=='(')
{
q=(LLS *)malloc(sizeof(LLS));
}
while(j<N)
{
pop(temp+j);
j++;
}
}
int main(void)
{
int i=0;
int train[10]={0,0,1,0,1,1,1,0,1,1};
int temp[10];
for(i=0;i<N;i++)
{
if(train[i]) printf("H ");
else printf("S ");
head.next->C=0;
k=str[i];
while(k!='\n')
{
switch(k)
{
case '+' : head.next->next->C=head.next->next->C + head.next->C;head.next->C=head.next->next->C;i++;break;
case '-' : head.next->next->C=head.next->next->C - head.next->C;head.next->C=head.next->next->C;i++;break;
case '*' : head.next->next->C=head.next->next->C * head.next->C;head.next->C=head.next->next->C;i++;break;
}
printf("\n");
Arrange(Ons,train,temp);
for(i=0;i<N;i++)
{
if(temp[i]) printf("H ");
else printf("S ");
}
system("pause");
return 0;
}
#include<stdio.h>
typedef struct LLS{
q->next=head.next;
head.next=q;
}
else if(k==')')
{
if(!head.next) return 1;
else head.next=head.next->next;
}
}
if(head.next) return 1;
else return 0;
}
int main(void)
else printf("pop is %d",*data);
}
system("pause");
}
return 0;
}
#include<stdio.h>
int * Ons=NULL;
int Point=0;
int N=10;
int push(int x)
{
Point++;
if(Point>N) return 1;
printf("Input :");
scanf("%s",str);
printf("\n");
printf("%s = %d\n",str,Count(str));
system("pause");
return 0;
}
#include<stdio.h>
int g(int m,int n)
{
if(m==0 && n>=0) return 0;
else if(n>0) return n*F1(n/2);
}
int F2(int n)
{
int sum=1;
if(n==0) return 1;
else if(n>0)
{
sum=n;
while(n/2!=0)
{
sum=sum*(n/2);
}
return 1;
}
int main()
{
while(1)
{
if(CmpS()) printf("Matched\n");
else printf("Not Matched!\n");
}
system("pause");
return 0;
}
#include<stdio.h>
typedef struct LLS{
else return 0;