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

مساعدة في stack

بدأه طــآلبة حآسب آلي . في 17 مايو 2011 · 30 رد · 1,637 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#26

جدا ,, امم مافهمت كويسس ,,

مع اني طول اليوم افكر كيف راح احله : )

لانه لسا باقي عندي سؤال الكيو ماحليته واختباري الاربعاء ,, فاكيد راح يفيدوني ..

بركز شوي .. واساسا لو تجيب لي مثال وتطلب البوستفكس اججيبه صح .. لكن ماعرف تمثيله بالسي ++

#27

كيف تحولي من infix الى postfix?

فس الانفكس التعبير يكون كذا

(3+4) *5

يعني بين كل عددين في اشارة، تمام علشان تحولي لبوست فيكس

تفحصي اول شي العدد اذا كان عدد ولا اشارة تروحي تدخليه اذا كان عدد تمام، بعدين اذا كان اشارة تحجزيه وتدخلي العدد الثاني بعدين تدخلي الاشارة

مثلا : اول شي بتدخلي ال3 تمام

ثاني شي ال+ تحتفظي بها

تدخلي ال4 بعدين تدخلي ال+ اللي كنتي محتفظه بها

بعد كذه معاكي ال* احتفظي به

بعد كذه دخلي ال5 بعدها دخلي ال*

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

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

void push(char [],int&,char);
char pop(char[],int &);
void main ()
{
char infex[30];
int choice ,top=-1,j=0;
char ch,value;
char sk[15];
char postfix[15];
do {
cout<<"1-convert from infex to postfix.\n"
<<"2-exit.\n"
<<"please enter your choice:";

cin>>choice;

if(choice==1)
{
cout<<"please enter the infex formula: ";
gets(infex);

for(int i=0;i<strlen(infex);i++)//loop for all infex formla
{ //check if infex is operation or digit
if(infex=='+'||infex=='-'||infex=='*'||infex=='/'||infex=='('||infex==')')//check if infex is operation
{

if(infex=='*'||infex=='/'||infex=='(')
push(sk,top,infex);//push the operation on the
//stack
else if(infex=='+'||infex=='-')//check if the
//operation(+)or
//(-)for priotiry
{
if(sk[top]=='*'||sk[top]=='/')//the priotiry for
//(*)&(/) before(+)&(-)
{
while(sk[top]!='('&&top>-1)//I pop all
// operation from stack then put them into
//postfix until found '('.if top=-1,I cannot
//pop
{
value=pop(sk,top);
postfix[j]=value;
j++;
}
push(sk,top,infex);//I push the oper. later
}
else
push(sk,top,infex);//I push the oper. if
//not found(*)or(/)
}
else if(infex==')')//the priority for'()' is major
{
while(sk[top]!='(')//I pop all
// operation from stack then put them into
//postfix until found '(' then skip it by
//top--;
{
value=pop(sk,top);
postfix[j]=value;
j++;
}
top--;
}
}



else
{postfix[j]=infex;//if infex not operation put it
//into postfix
j++;
}
}
while(top>-1)//pop all remainder operation from the stack then
//put it into postfix.
{
value=pop(sk,top);
postfix[j]=value;
j++;
}
postfix[j]='\0';
cout<<"the formula after its convert to postfix is= "<<postfix;
}
else if(choice==2)
exit(0);

else
{

cout<<"Your enter is invalid...\n"
<<"\nnAre you want try again? Y/N\n";
cin>>ch;
}
//Now I compute the formula
for(int i=0;i<strlen(postfix);i++)
{
if(postfix=='+'||postfix=='-'||postfix=='*'||postfix=='/'||postfix=='('||postfix==')')
{
int a,b,c;
value=pop(sk,top);
a=value-48;
value=pop(sk,top);
b=value-48;
if(postfix=='+')
c=a+b;
else if(postfix=='-')
c=a-b;
else if(postfix=='*')
c=a*b;
else
c=a/b;
value=c+48;
push(sk,top,value);
}
else
push(sk,top,postfix);
}
value=pop(sk,top);
int result=value-48;
cout<<"\nthe result= "<<result;
cout<<"\nAre you want try again? Y/N\n";
cin>>ch;
getch();
//clrscr();
}while(ch=='Y'||ch=='y');
}
//end main--------------------------------------------

//begin function push
void push(char sk[15],int&top ,char value)
{
if(top<14)
{
top++;
sk[top]=value;
}
else
cout<<"Stack is FULL...";
}//end push
//----------------------------------------------


//begin function pop
char pop(char sk[15],int &top)
{ char v;
if(top>-1)
{
v=sk[top];
top--;
}
else
cout<<"Stack is EMPTY....";
return v;
}//end function

أنا فاهمة عليك ..

اممم

هذا الكود شبيه لكودي السابق ,,

واحس لو اني افهمه بيساعدني اكتب كودي : )

مع اني كنت ابغى اسويه بدون مااشوف اكواد غيري :(

بس خلاص اهم شي اسويه قبل اختباري ..

يآآ ليت تششرحه لي لوفهمته

تم تعديل هذه المشاركة بواسطة طــآلبة حآسب آلي . في 23 مايو 2011 في 21:54

#29

والله عندي ضروف خارجه عن ارادتي حتى تواجدي في المنتدى خلال هذه المده سيكون قليل

ان كان في كلامي عزاء لكي : اكتبي مثال بيدكي مثلا

(4+5)*(2-3)/3

بعدين اعملي محاكاه للكود بيدك على الورق وبيفتهم لك إن شاء الله

اعتذر مره اخرى ولكنها ضروف خارجه عن الاراده ، واتمنى لو ان هناك اعضاء اخرون يستطيعون المساعده

1

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#30

شكرا لك كثيرا ي اخي ,,

والله انك ساعدتني كثييرا ,

اسال الله أن يكتب لك الأجر , وييرزقك توفيقا وفلاحا ..

. ويبدو ليس هناك سواك مهتم بموضوع الستاك ..

لكني سأسأل ., لعل احد ما يجيب ..

كتبت هذا الكود , والمفترض بأنه يطبع عناصر الستاك بالعكس ,,

#include<iostream.h>
#include<process.h>
struct stack{
	stack s1,s2;
	int info;
};
class  stacks {
private:
stack top;
int x;
public:
	s1.stack(){top=-1;}	
	s2.stack(){top=-1;}
	void menu(){
		int choice;
		cout<<"\n1- push ,,,, 2- pop ,,,,, 3- traverse ,,, ,,5-exit\n";
		cin>>choice;
		switch(choice)
		{
		case 1:
				cout<<"enter num";
				cin>>x;
				s1.push (x);}
			break;
		case 2:
			if(isempty())
				cout<<"empty";
			else {
				x=s1.pop();
				cout<<"num delder="<<x;
				s2.push(x);
				cout<<"num enter="<<x;
			}
			break;
		case 3:
	if(isempty())
				cout<<"empty";
	else {
		cout<<"the list is ";
		s1.traverse();}
		break;

		case 4:
			exit(0);
		default:
			cout<< " invalid choice ";
		} 
	}

bool isempty( )
{
	if (top==-1)
		return true ;
	else
		return false ;
} 
	void traverse() {
stack *i;
do{
	cout<<i->info;
	i=i->next;
}
while(i!=NULL);
	}



	void push(int x){

			stack *p=new stack;
			p->info=x;
			p-<next=NULL;
			if(top==NULL)
				top=p;
			else 
			{
				p->next=top;
				top=p;
	}
	int pop()
	{
		stack*t;
		x=top->info;
		x=top;
		top=top->next;
		delste t;
		return x;
	}
};


	void main()
	{ 
		stacks m;
	while (1)
	m.menu();
}
#31

بليز ضروري أريد أحد يسساعدني بكود لتمثيل الستاك باستخدام 2 queue ..

والعكس تمثيل queue باستخدام 2 ستاك

بليز اختباري بكرا ومو عارفة كيف احللها تعبت والله

:(

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

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…