91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

數(shù)據(jù)結(jié)構(gòu)表達式求值,c語言版,能計算多位數(shù),下載后可以直接運行,注釋明確

資源截圖

代碼片段和文件信息

#include
#include
#include
//操作數(shù)棧的定義及操作
#define?max?1000
typedef?struct
{
double?data[max];
int?top;
}SeqStack*PseqStack;
//初始化一個空棧
PseqStack?Init_Stack(void)
{
PseqStack?s;
s=(PseqStack)malloc(sizeof(SeqStack));
if(s)
s->top=-1;
return?s;
}
//判斷棧是否為空
int?Empty_Stack(PseqStack?s)
{
if(s->top==-1)
return?1;
else
return?0;
}
//元素入棧
int?Push_Stack(PseqStack?sdouble?x)
{
if(s->top==max-1)
{
printf(“棧滿,不能入棧!\n“);
return?0;??????????//棧滿不能入棧
}
else
{
s->top++;
s->data[s->top]=x;
return?1;
}
}
//元素出棧
int?Pop_Stack(PseqStack?sdouble?*x)
{
if(Empty_Stack(s))
{
printf(“???,無元素出棧!\n“);
return?0;
}
else
{
*x=s->data[s->top];
s->top--;
return?1;
}
}
//取棧頂元素
int?Get_Stack(PseqStack?sdouble?*x)
{
if(Empty_Stack(s))
{
printf(“???\n“);
return?0;
}
else
{
*x=s->data[s->top];
return?1;
}
}
//銷毀棧
void?Destory_Stack(PseqStack?*s)
{
if(*s)
free(*s);
*s=NULL;
}
#define?M?100
//操作符棧的定義及操作
typedef?struct
{
char?data[M];
int?top;
}seqstack*pseqstack;
pseqstack?Init_stack()
{
pseqstack?s;
s=(pseqstack)malloc(sizeof(seqstack));
if(s)
s->top=-1;
return?s;
}
//判斷???br/>int?Empty_stack(pseqstack?s)
{
if(s->top==-1)
return?1;
else
return?0;
}
//入棧
int?Push_stack(pseqstack?schar?x)
{
if(s->top==M-1)
{
printf(“棧滿!“);
return?0;
}
else
{
s->top++;
s->data[s->top]=x;
return?1;
}
}
//元素出棧
int?Pop_stack(pseqstack?schar?*x)
{
if(Empty_stack(s))
{
return?0;
}
else
{
*x=s->data[s->top];
s->top--;
return?1;
}
}
//獲取棧頂元素
int?Gettop_stack(pseqstack?schar?*x)
{
if(Empty_stack(s))
{
return?0;
}
else
{
*x=s->data[s->top];
return?1;
}
}
//銷毀棧
void?Destory_stack(pseqstack?*s)
{
if(*s)
free(*s);
*s=NULL;
return?;
}
//判斷讀入的字符是否是數(shù)字
int?IsNum(char?c)
{
if(c>=‘0‘&&c<=‘9‘)
return?1;
else
return?0;
}?????????????
//返回運算符優(yōu)先級
int?Priority(char?op)
{
switch(op)
{
case‘=‘:return?1;
case‘)‘:return?2;
case‘+‘:
case‘-‘:return?3;
case‘*‘:
case‘/‘:return?4;
case‘(‘:return?5;
default:return?0;
}
}
//對中綴表達式直接求值
double?Infix_exp_value(char?*infixexp)
{
PseqStack?s1;?????????//操作數(shù)
pseqstack?s2;?????????//操作符
char?wtopelementch;
double?abcsumresult;
s1=Init_Stack();
s2=Init_stack();
if(!s1||!s2)
{
printf(“?to?initialize?a?stack?is?false!“);
return?0;
}
Push_stack(s2‘=‘);
w=*infixexp;
while((Gettop_stack(s2&ch)ch)!=‘=‘||w!=‘=‘)???????//取棧頂元素,判斷是否是數(shù)字
{
if(IsNum(w))?????????????????????????????????????//對數(shù)字處理
{
sum=0;
sum=w-‘0‘;
infixexp++;
w=*infixexp;
while(IsNum(w))
{
sum=sum*10+(w-‘0‘);
infixexp++;
????w=*infixexp;
}
Push_Stack(s1sum);
}
else??????????????????????????????????//對運算符的處理
{
if(Priority((Gettop_stack(s2&ch)ch))>Priority(w)&&(Gettop_stack(s2&ch)ch)!=‘

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件?????192613??2013-05-30?21:16??infixexp_value_wei\Debug\infixexp_value_wei.exe

?????文件?????201664??2013-05-30?21:16??infixexp_value_wei\Debug\infixexp_value_wei.ilk

?????文件??????16229??2013-05-30?21:16??infixexp_value_wei\Debug\infixexp_value_wei.obj

?????文件?????225888??2012-06-06?19:56??infixexp_value_wei\Debug\infixexp_value_wei.pch

?????文件?????476160??2012-06-18?09:42??infixexp_value_wei\Debug\infixexp_value_wei.pdb

?????文件??????41984??2013-05-30?21:17??infixexp_value_wei\Debug\vc60.idb

?????文件??????53248??2012-06-18?09:42??infixexp_value_wei\Debug\vc60.pdb

?????文件???????4528??2012-06-18?09:42??infixexp_value_wei\infixexp_value_wei.cpp

?????文件???????4428??2012-03-28?13:49??infixexp_value_wei\infixexp_value_wei.dsp

?????文件????????561??2012-03-28?12:28??infixexp_value_wei\infixexp_value_wei.dsw

?????文件??????41984??2013-05-30?21:17??infixexp_value_wei\infixexp_value_wei.ncb

?????文件??????48640??2013-05-30?21:17??infixexp_value_wei\infixexp_value_wei.opt

?????文件????????955??2013-05-30?21:16??infixexp_value_wei\infixexp_value_wei.plg

?????目錄??????????0??2013-08-01?11:31??infixexp_value_wei\Debug

?????目錄??????????0??2013-08-01?11:31??infixexp_value_wei

-----------?---------??----------?-----??----

??????????????1308882????????????????????15


評論

共有 條評論

相關(guān)資源