الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

تحويل من infix إلى postfix باستخدام الstack

مغلق
بدأه Mrs.Questions في 3 أبريل 2005 · 1 رد · 3,604 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم أولا ...

الموضوع إنه في برنامج أنا سويته ( فكرته : تحويل من infix إلى postfix باستخدام ال stack وحساب الناتج ) المشكلة إنه مشي معايا بس ال run مو راضي يظبط معايا مني عارفة ايش المشكلة في البرنامج....

infix = (6+2)*5-8/4

postfix = 62+5*84/- for the same equation

الله يخليكم بس اللي يعرف أيش الغلط في البرنامج

والسؤال الثاني كيف يسير الكود لو حولته إلى linked list

ومشكوريـــــن ألـــف شكر ...

أختكم MRS.QUESTIONS

الكود :

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>

void push(int array1[],int value,int &top); 
int pop(int array2[],int &top);
const int max=20;

void main ()
{
	int top=-1;
	char exp[max];
	int operand[10],operatr[10];

	cout <<"enter ur expression: \n";
	gets(exp);
	int length=strlen(exp);
	for (int i=0;i<=length;i++)
	{
  if ((exp>=1)||(exp<=9))
 	 push(operand,exp,top);
  else if ((exp=='+')||(exp=='-')||(exp=='*')||(exp=='/'))
  {
 	 if ((top=='+')||(top=='-')||(top=='*')||(top=='/'))
 	 {
    if (((top=='+')||(top=='-'))&&((exp=='*')||(exp=='/')))
   	 push(operatr,exp,top);
    else if (((top=='*')||(top=='/'))&&((exp=='+')||(exp=='-')))
    {
   	 int x=pop(operand,top);
   	 int y=pop(operand,top);
   	 int z=pop(operatr,top);
   	 switch(z)
   	 {
   	 case '+':
      {
     	 push(operand,x+y,top);
     	 break;
      }
   	 case '-':
      {
     	 push(operand,x-y,top);
     	 break;
      }
   	 case '*':
      {
     	 push(operand,x*y,top);
     	 break;
      }
   	 case '/':
      {
     	 push(operand,x/y,top);
     	 break;
      }
   	 }
   	 push(operatr,exp,top);
    }
    else 
    {
   	 do{
      int x1=pop(operand,top);
         int y1=pop(operand,top);
         int z1=pop(operatr,top);
   	 switch(z1)
   	 {
   	 case '+':
      {
     	 push(operand,x1+y1,top);
     	 break;
      }
   	 case '-':
      {
     	 push(operand,x1-y1,top);
     	 break;
      }
   	 case '*':
      {
     	 push(operand,x1*y1,top);
     	 break;
      }
   	 case '/':
      {
     	 push(operand,x1/y1,top);
     	 break;
      }
   	 }
   	 }while(exp!=' ');
    }
 	 }
  }
	}
	getch();
}

//**********************************************************************
void push(int array1[],int value,int &top)
{
	if (top<max-1)
	{
  top++;
  array1[top]=value;
	}
	else 
  cout<<"stack is full";
}

//*********************************************************************
int pop(int array2[],int &top)
{
	if (top>-1)
	{
  int x=array2[top];
  top--;
  return x;
	}
	else 
  cout<<"stack is empty";
}
#2

ياجماعة مافي أحد يقدر يساعدني ؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟ :s :s :s :s

هذا الموضوع مغلق.

مواضيع مشابهة