⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pretoin.c

📁 This source code is used for make infix expression from prefix expression by using assembly and C la
💻 C
字号:
#include "pretoin.h" /*Standart library ,structure and function prototip in this header*/int main( int argc , char* argv[] ){		process();	return 1;	}/*Start the program execution  * Function get the input from standart input while this is not EXIT *Input is prefix expression create tree for it than write it infix notation and result */void process(){		tree_ptr top; /*top pointer of tree*/	/*evaluation is keep input string which is prefix notation 	 * expression is keep infix notation of evaluation*/	char *evaluation , *expression;		/*get the evaluation string from stdin */	getEvaluation ( &evaluation );	/*EXIT is finish the program else get new evaluation string*/	while( strcmp( evaluation , "EXIT" ) != 0 ){				int evaluationLength = strlen( evaluation );		create_tree( &top , evaluation ,evaluationLength );		/*expression is infix notation and infix notation have pharantesis and eaxh operator there is two pharantesis*/		expression = (char *) malloc( sizeof( char ) * (evaluationLength + (((evaluationLength *2 )/3)+1) ) );				inorder( top , expression );				printf( "Result:%s=" , expression );				printf( "%0.2f\n" , calculate( top ) );				/*get the evaluation string from stdin */		getEvaluation ( &evaluation );			} 	/*free the all getting char* */	free( expression );	free( evaluation );}/*Make a tree node get node data and set left and right child null and return new tree_ptr*/tree_ptr get_node( char data ){	tree_ptr tree_node = ( tree_ptr ) malloc( sizeof( tree_node ) );		tree_node->data = data; /*set data*/	tree_node->leftChildPtr = NULL; /*set child NULL*/	tree_node->rightChildPtr = NULL;		return tree_node; /*return the new tree node*/	} /*get the evaluation string from stdin and return string lenght * firstly size 4 than it grow multiple 2*/int getEvaluation( char **evaluation ){		int indice = 0 , malloc_size = 4;		*evaluation = ( char * ) malloc( sizeof( char ) * malloc_size );		while( ( (*evaluation)[ indice] = ( char ) getchar() ) != '\n' ){				indice++;				if( indice == malloc_size ){			*evaluation = ( char* ) realloc(  *evaluation , malloc_size *2 );			malloc_size *=2;		}	}		(*evaluation)[ indice] = '\0';		return indice;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -