資源簡介
幫別人寫的一個C/C++程序,輸入兩個字符串表達式,輸入要合法,解析字符串,計算,例如 x + y, x -y,計算,,前一久寫的程序,測了一下可以用,沒有深入測試了,放在機子上也是放著,今天上傳一下,弄點積分,謝謝大家?。。。?!

代碼片段和文件信息
//?MyPrograms.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?“stdio.h“
#include?
#include?
#include?
#include?
#include?
typedef?struct?_TVariable??
{
char?Variable;???//字母變量
int?VariableDegree;//字母變量的次數(shù)
int?nMutiplied;?????????????????????//這個系數(shù)是否已經(jīng)乘過???0:?no??1:?yes
struct?_TVariable?*pNextVariable;
}TVariable?*PVariable;
typedef?struct?_TItem
{
int?nCoefficient;????//多項式的系數(shù)
PVariable?pVariable;???????//??指向字母鏈表
struct?_TItem?*pNextItem;?//
}TItem?*PItem;
/*
typedef?enum?CURRENT_POSITION
{
BEFORE_LETTER??=?0???//字母前面是系數(shù)
????AFTER_LETTER???=?1???//字母后面為次數(shù)
};
CURRENT_POSITION?g_CurrPosition?=?BEFORE_LETTER;
*/
PItem?g_FirstDataHead?=?NULL;
PItem?g_SecondDataHead?=?NULL;
PItem?g_MutiResultHead?=?NULL;
char*?g_InputData?=?NULL;
//單個聯(lián)表內(nèi)存的釋放
void?FreeSpace(PItem?g_pItems)
{
while?(g_pItems)?//釋放多項式鏈表
{
PItem?pItemTemp?=?g_pItems->pNextItem;
PVariable?pVar?=?g_pItems->pVariable;
while(pVar)//釋放字母變量的聯(lián)表
{
PVariable?pVarTemp?=?pVar->pNextVariable;
free(pVar);
pVar?=?pVarTemp;
}
free(g_pItems);
g_pItems?=?pItemTemp;
}
}
//釋放內(nèi)存
void?FreeMallocSpace()
{
FreeSpace(g_FirstDataHead);
FreeSpace(g_SecondDataHead);
FreeSpace(g_MutiResultHead);
}
int?Find_0_9()//讀出緊挨著的連續(xù)的數(shù)字
{
char?StoreValue[100]?=?{0};
int?i?=?0;
while(*g_InputData?<=?‘9‘?&&?*g_InputData?>=?‘0‘)
{
StoreValue[i]?=?*g_InputData;
i++;
g_InputData++;
}
return?atoi(StoreValue);
}
//剛進來,??*g_InputData一定是字母
void?DisposeLetter(PItem?pData)//解析字母以及???字母之間的數(shù)字(字母的系數(shù)系數(shù)不能為負數(shù))
{
/* PVariable?pLast?=?pData->pVariable;
PVariable?pVarble?=?NULL;
while(!(*g_InputData?==?‘+‘?||?*g_InputData?==?‘-‘?||?*g_InputData?==?‘\0‘))
{
if(*g_InputData?<=?‘9‘?&&?*g_InputData?>=?‘0‘)
{
pVarble->VariableDegree?*=?Find_0_9();
}
else?if((*g_InputData?<=?‘Z‘?&&?*g_InputData?>=?‘A‘)?||?(*g_InputData?<=?‘z‘?&&?*g_InputData?>=?‘a(chǎn)‘))
{
pVarble?=?(PVariable)malloc(sizeof(struct?_TVariable));
memset(pVarble?0?sizeof(struct?_TVariable));
pVarble->Variable?=?*g_InputData;
pVarble->VariableDegree?=?1;
pLast->pNextVariable?=?pVarble;
pLast?=?pVarble;
g_InputData++;
}
}
*/
//建立字母鏈表
if((*g_InputData?<=?‘Z‘?&&?*g_InputData?>=?‘A‘)?||?(*g_InputData?<=?‘z‘?&&?*g_InputData?>=?‘a(chǎn)‘))
{
PVariable?pLast?=?NULL;
PVariable?pVarble?=?(PVariable)malloc(sizeof(struct?_TVariable));
memset(pVarble?0?sizeof(struct?_TVariable));
pData->pVariable?=?pVarble?;???//字母
pLast?=?pVarble;
pVarble->Variable?=?*g_InputData;
pVarble->VariableDegree?=?1;???//字母次數(shù)為1
g_InputData++;
while(!(*g_InputData?==?‘+‘?||?*g_InputData?==?‘-‘?||?*g_InputData?==?‘\0‘))
{
if(*g_InputData?<=?‘9‘?&&?*g_InputData?>=?‘0‘)
{
pVarble->VariableDegree?*=?Find_0_9();?//字母之后的數(shù)字一定是,字母的次數(shù),
}
else?if((*g_InputData?<=?‘Z‘?&&?*g_InputData?>=?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????14267??2009-06-20?15:03??MyPrograms\MyPrograms.cpp
?????文件???????4582??2009-06-20?00:00??MyPrograms\MyPrograms.dsp
?????文件????????543??2009-06-17?19:03??MyPrograms\MyPrograms.dsw
?????文件??????66560??2009-06-20?15:03??MyPrograms\MyPrograms.ncb
?????文件??????54784??2009-06-20?15:03??MyPrograms\MyPrograms.opt
?????文件???????1092??2009-06-20?15:03??MyPrograms\MyPrograms.plg
?????文件???????1232??2009-06-17?19:03??MyPrograms\ReadMe.txt
?????文件????????297??2009-06-17?19:03??MyPrograms\StdAfx.cpp
?????文件????????667??2009-06-17?19:03??MyPrograms\StdAfx.h
?????目錄??????????0??2009-06-27?22:56??MyPrograms
-----------?---------??----------?-----??----
???????????????144024????????????????????10
評論
共有 條評論