int main(void) 
{
  Poly p;

  p = POLYadd(POLYterm(1, 5, 3), POLYterm(1, 1, 4));
  showPOLY(p);
  printf("\n");
  return 0;
}
Exemple #2
0
Fichier : main.c Projet : dearxxj/C
int main(void) 
{
	int i = 0, N = 0;
	Item tmp;
	char *a = (char *)malloc(Nmax * sizeof(char));

	printf("Enter a postfix expression: \n");
	while ((a[i++] = getchar()) != '\n');
	N = i - 1;
	STACKinit(N);
	for (i = 0; i < N; i++)
	{
		if (a[i] == '+') 
		{
			STACKpush(POLYadd(STACKpop(), STACKpop()));
			continue;// 1
		}
		if (a[i] == '*')
		{
			STACKpush(POLYadd(STACKpop(), STACKpop()));
			continue;// 2
		}
		/*if (a[i] == '-') 
		{
			tmp = STACKpop();
			STACKpush(STACKpop() - tmp);
			continue;// 1
		}
		if (a[i] == '/') 
		{
			tmp = STACKpop();
			STACKpush(STACKpop() / tmp);
			continue;// 1
		}*/
		if ((a[i] >= '0') && (a[i] <= '9'))// 以下三行 把相邻的数字字符组合成十进制整数 
			STACKpush(POLYterm(0, 0));
		while ((a[i] >= '0') && (a[i] <= '9'))
			STACKpush(POLYadd(POLYmult(STACKpop(), POLYterm(1, 1)), POLYterm((a[i++] - '0'), 0)));
		if (a[i] != ' ') i--; // 3
											//1, 2, 3 使得+*和数字之间没有空格也能运行正确 
		
	}
	printf("%d \n", STACKpop());
	return 0;
}