求高手前来指导小弟因为数据结构课程设计遇到了问题,课程设计的题目为魔王语言的翻译,问题描述有一个魔

#include<stdio.h>#defineMAX50typedefstruct//栈结构体{chare[MAX];inttop;}SeqStack;typedefs... #include<stdio.h>
#define MAX 50
typedef struct//栈结构体
{
char e[MAX];
int top;
}SeqStack;
typedef struct NODE//队列结构体
{
char d;
struct NODE *next;
}LinkQN;
typedef struct//封装头指针为指针
{
LinkQN *front;
LinkQN *rear;
}LinkQ;

SeqStack *InitS()//初始化顺序栈
{
SeqStack *s;
s=(SeqStack *)malloc(sizeof(SeqStack));
s->top=-1;
return(s);
}
int push(SeqStack *s,char ch)//入栈
{
if(s->top==MAX-1)
return(0);
s->top++;
s->e[s->top]=ch;
return(1);
}
int pop(SeqStack *s,char *x)//出栈
{
if(s->top==-1)
return(0);
*x=s->e[s->top];
s->top--;
return(1);
}
int ISemptySt(SeqStack *s)
{
if(s->top==-1)
return 1;
return 0;
}
void InitQ(LinkQ *q)//链队列初始化
{
q->front=(LinkQN *)malloc(sizeof(LinkQN));
if(!q->front)
{
printf("分配空间失败!");
}
q->rear=q->front;
q->front->next=NULL;
}
int enter(LinkQ *q,char ch)//入队
{
LinkQN *np;
np=(LinkQN *)malloc(sizeof(LinkQN));
if(!np)
return(0);
np->d=ch;
np->next=NULL;
q->rear->next=np;
q->rear=np;
return(1);
}
int deleteq(LinkQ *q,char *c)//出队
{ LinkQN *p;
if(q->front==q->rear)
return(0);
p=q->front->next;
q->front->next=p->next;
if(q->rear==p)
q->rear=q->front;
*c=p->d;
free(p);
return(0);
}
int IsemptyQu(LinkQ *q)
{
if(q->rear==q->front)
return 1;
return 0;

}
void deletkuohao()
{
SeqStack *s1,*s2;
LinkQ *q1,*q2;
int i,count=0,t=0;//count记录“(”的个数,t记录魔王语言中字符的个数
char ch,ch1,temp;
char a[MAX];
s1=InitS();
s2=InitS();
InitQ(&q1);
InitQ(&q2);
printf("请输入魔王要说的语言:");
scanf("%s",a);
for(i=0;a[i]!='\0';i++)
{ t++;
if(a[i]==')')
count++;//
}
printf("%d%5d\t",count,t);
for(i=t;i>=0;i--)//逆序入栈
{
push(s1,a[i]);
}
while(count!=0)
{

pop(s1,&ch);
while(ch!=')')
{
push(s2,ch);
pop(s1,&ch);
}
pop(s2,&ch);
while(ch!='(')
{
enter(&q1,ch);
temp=ch;
pop(s2,&ch);
}

while(!IsemptyQu(&q1))
{
deleteq(&q1,&ch);
enter(&q2,temp);
enter(&q2,ch);
}
deleteq(&q2,&ch); //问题:刚开始的时候程序运行到此处才弹出那个ox什么的引用的内存不能为read的那个框的,
while(!IsemptyQu(&q2))
{
deleteq(&q2,&ch);
push(s2,ch);
}
while(!ISemptySt(s2))
{
pop(s2,&ch);
push(s1,ch);
}
count--;
}
while(!ISemptySt(s1))//测试下是否按照去括号法则进行
{
pop(s1,&ch);
printf("%c",ch);
}
}
小弟初学程序设计,还有很多问题不懂,希望个位大哥大姐不吝赐教,感激不尽……
问题描述有一个魔王总是使用自己的一种非常精炼而抽象的语言讲话,没有人能听懂。但他的语言是可以逐步解释成人能懂的语言的,因为他的语言是由以下两种形式的规则由人的语言逐步抽象上去的:
(1)α→β1β2 …… βm
(2)(θδ1δ2 …… δn)→ θδnθδn-1 …… θδ1 θ
在这两种形式中,从左到右均表示解释;从右到左均表示抽象。试写一个魔王语言的解释系统,把他的话解释成人能听得懂的话。 小弟在去括号时遇到了麻烦,这些是去括号的代码,以及栈和队列的基本的操作
展开
 我来答
luzhongkailove
2010-11-29 · 超过24用户采纳过TA的回答
知道答主
回答量:130
采纳率:0%
帮助的人:84万
展开全部
这个问题比较难回答!请百度一下,不行的话去google
瓷起05
2010-11-25 · TA获得超过3991个赞
知道小有建树答主
回答量:2354
采纳率:0%
帮助的人:1658万
展开全部
用对列解

n个人排队开始数数
数的数<m的元素重新排队(当前数据删除添加到队尾)
数到第m的元素直接从队列中删除
如此循环直到队列的元素=k为止
我可以帮助你,你先设置我最佳答案后,我百度Hii教你。
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
plnsa63
2010-11-28 · TA获得超过278个赞
知道答主
回答量:243
采纳率:0%
帮助的人:0
展开全部
一元多项式计算**
(任务:能够按照指数降序排列建立并输出多项式)
能够完成两个多项式的相加、相减,并将结果输入;在上交资料中请写明:存储结构、多项式相加的基本过程的算法(可以使用程序流程图)

、源程序、测试数据和结果。
#include <dos.h>
#include <stdio.h>
#include <conio.h>
struct pnode
{int ceof;/*多项式中项的系数*/
int exp;/*多项式中项的指数*/
struct pnode *link;
};
main()
{
int id;
clrscr();
printf("0 多项式相加 1 多项式相减minus\n");
/*while(id='0' or id='1')*/
do
{id=getch();
switch(id)
{case '0':
printf("this is plus");
plusdss();
break;
case '1':
printf("this is minus");
/*minusdss();*/
break;
default:
break;
}
}while(id!='0'&&id!='1');
}

struct pnode *padd(heada,headb)
struct pnode *heada,*headb;
{
struct pnode *headc,*p,*q,*s,*r;
int x;
p=heada;
q=headb;
headc=(struct pnode*)malloc(sizeof(struct pnode));
r=headc;
while(p!=NULL&&q!=NULL)
{if(p->exp==q->exp)
{
x=p->ceof+q->ceof;
if(x)
{
s=(struct pnode*)malloc(sizeof(struct pnode));
s->ceof=x;
s->exp=p->exp;
r->link=s;
r=s;
}
p=p->link;
q=q->link;
}
else
if(p->exp>q->exp)
{s=(struct pnode*)malloc(sizeof(struct pnode));
s->ceof=q->ceof;
s->exp=q->exp;
r->link=s;
r=s;
q=q->link;
}
else
{s=(struct pnode*)malloc(sizeof(struct pnode));
s->ceof=p->ceof;
s->exp=p->exp;
r->link=s;
r=s;
p=p->link;
}
}
while(p!=NULL)
{
s=(struct pnode*)malloc(sizeof(struct pnode));
s->ceof=p->ceof;
s->exp=p->exp;
r->link=s;
r=s;
p=p->link;
}
while(q!=NULL)
{
s=(struct pnode*)malloc(sizeof(struct pnode));
s->ceof=q->ceof;
s->exp=q->exp;
r->link=s;
r=s;
q=q->link;
}
r->link=NULL;
s=headc;
headc=headc->link;
free(s);
return(headc);
}
/*建立多项式*/
struct pnode *inputdss()
{
struct pnode *head,*s,*r;
int n,m;
head=(struct pnode*)malloc(sizeof(struct pnode));
r=head;
s=head;
printf("PUT IN CEOF N= ");
scanf("%d",&n);
while(n!=0)
{printf("put in exp m=");
scanf("%d",&m);
s=(struct pnode*)malloc(sizeof(struct pnode));
s->ceof=n;
s->exp=m;
r->link=s;
r=s;
printf("PUT IN CEOF N=");
scanf("%d",&n);
}
s->link=NULL;
head=head->link;
express(head);
sort(&head);
express(head);
return(head);
}

plusdss()
{struct pnode *a,*b,*c;
a=inputdss();
b=inputdss();
c=padd(a,b);
express(c);
}
/*输出多项式*/
express(head)
struct pnode *head;
{
struct pnode *s;
printf("the express is");
if(head!=NULL)
{printf("%d",head->ceof);
printf("X^");
printf("%d",head->exp);
s=head->link;
while(s!=NULL)
{
if(s->ceof>0)
printf("+");
printf("%d",s->ceof);
printf("X^");
printf("%d",s->exp);
s=s->link;
}
}
printf("\n");
}
/*多项式按指数排序*/
sort(head1)
struct pnode **head1;
{
struct pnode *p,*q,*r,*h1,*s;
h1=p=(struct pnode*)malloc(sizeof(struct pnode));
p->link=*head1;
while(p->link!=NULL)
{
q=p->link;
r=p;
while(q->link!=NULL)
{
if(q->link->exp<r->link->exp) r=q;
q=q->link;
}
if(r!=p)
{s=r->link;
r->link=s->link;
s->link=p->link;
p->link=s;
}
p=p->link;
}
*head1=h1->link;
free(h1);
printf("ok");
}
这是我自己的问题啊,希望大家帮忙啊!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式