begin process at 2008 07 06 12:54:39
1 205 544 membres
121 nouveaux aujourd'hui
14 119 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

NOTATION POLONAISE INVERSE


Information sur la source

Catégorie :Maths & Algorithmes Niveau : Débutant Date de création : 09/01/2005 Vu : 3 449

Note :
7 / 10 - par 1 personne
7,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (4)
Ajouter un commentaire et/ou une note

Description

Ce code réalise ce qu'on appelle la notation polonaise inverse.
elle consiste à effectuer des opérations arithmétiques étant donné des opérateurs et des opérandes.les opérandes son tplacés avant les opérateurs(par exemple 5 6 +   càd  5+6) (autre exemple  5 6 + 2 3 * -
càd  (5+6)-(2*3)).Pour cela j'ai mis en oeuvre la notion de pile.SI vous executer ce programme  essayer de respecter la régle de saisie comme indiqué dans le s2 exemples précedents.
Vous verez que vous n'aurez le droit de saisir que des entiers entre 0  et 9.si vous examinez bien le code vous verez pourqoui et vous verez aussi qu'il est très facile de le modifier si vous voulez entrez des entiez positifs supérieur à 9.
Pour simplifier on utilise que des entiers positifs.  

Source

  • #include<stdio.h>
  • #include<conio.h>
  • #include<stdlib.h>
  • struct ma_pile{
  • char info;
  • struct ma_pile *suiv;
  • };
  • /****************** declaration Variables globales *****************/
  • struct ma_pile *sommet;
  • char p1;
  • char ch[20],c;
  • int i=0,code=0;
  • char tempo[2];
  • /****************** ce qui suit est des fonctions *********************/
  • struct ma_pile *Init(struct ma_pile **sommet)
  • {
  • *sommet=NULL;
  • return *sommet;
  • }
  • int char_to_int(char c)
  • {
  • if(c=='0')
  • return code==0;
  • else
  • {
  • code=c-48;
  • return code;
  • }
  • }
  • char int_to_char(int int_to_ch)
  • {
  • int_to_ch+=48;
  • c=(char)int_to_ch; // converti l'ascii int_to_char en caractere
  • return c;
  • }
  • void EMP(char x,struct ma_pile **sommet)
  • {
  • struct ma_pile *p;
  • p=(struct ma_pile *)malloc(sizeof(struct ma_pile));
  • p->info=x;
  • p->suiv=*sommet;
  • *sommet=p;
  • }
  • int DEP(struct ma_pile **sommet)
  • {
  • if(*sommet==NULL)
  • printf("E R R E U R ! LA PILE EST VIDE");
  • else
  • {
  • struct ma_pile *p=*sommet;
  • p1=p->info;
  • *sommet=p->suiv;
  • free(p);
  • printf("\nOPERATION SUCCESS\n");
  • printf("VALEUR DEPILEE :%d\n",char_to_int(p1));
  • return p1;
  • }
  • }
  • void saisie(char t[1])
  • {
  • char c;
  • int j1=0;
  • do
  • {
  • c=getch();
  • if(((c>='0')&& (c<='9')) || ((c=='*')|| (c=='-')|| (c=='+')|| (c=='/')))
  • {
  • if((c>='0')&& (c<='9'))
  • {
  • j1++; //comptabilise les caracteres entre '0' et '9'
  • if(j1>2)
  • printf("ACTION NON AUTORISEE\n");
  • else
  • {
  • t[i]=c;
  • printf("%c\n",t[i]);
  • i++;
  • }
  • }
  • if((c=='*')|| (c=='-')|| (c=='+')|| (c=='/'))
  • {
  • j1=0;
  • t[i]=c;
  • printf("%c\n",t[i]);
  • i++;
  • }
  • }
  • }
  • while(c!=13);
  • }
  • void VISU(struct ma_pile *sommet)
  • {
  • if(sommet!=NULL)
  • {
  • struct ma_pile *p=sommet;
  • while(p) {
  • printf("%c ->",p->info);
  • p=p->suiv; }
  • }
  • else
  • printf("E R R E U R ! VEUILLEZ D'ABORD REMPLIR LA PILE ");
  • }
  • void Traitement(char t[1])
  • {
  • int k,k1,code2=0,code1=0,resultat=0;
  • char c;
  • for(k=0;k<i;k++)
  • {
  • if ((t[k]>='0') &&(t[k]<='9'))
  • EMP(t[k],&sommet);
  • if((t[k]=='*')|| (t[k]=='-')|| (t[k]=='+')|| (t[k]=='/'))
  • {k1=1; //on commence … d‚piler
  • while((sommet!=NULL) && (k1>=0)) //ne depile que les 2 1ere valeurs
  • {
  • DEP(&sommet);
  • tempo[k1]=p1;
  • k1--;
  • }
  • code1=char_to_int(tempo[0]);
  • code2=char_to_int(tempo[1]);
  • switch (t[k])
  • {
  • case '+':resultat=code1+code2;printf("%d+%d=%d\n",code1,code2,resultat);
  • break;
  • case '-':resultat=code1-code2;printf("%d-%d=%d\n",code1,code2,resultat);
  • break;
  • case '*':resultat=code1*code2;printf("%d*%d=%d\n",code1,code2,resultat);
  • break;
  • case '/':resultat=code1/code2;printf("%d/%d=%d il s'agit d'une division entiŠre\n",code1,code2,resultat);
  • break;
  • }
  • EMP(int_to_char(resultat),&sommet);
  • }
  • }
  • }
  • /***********************
  • Fin des fonctions **********/
  • /***********************
  • Ceci est mon programme****/
  • void main()
  • {
  • clrscr();
  • saisie(ch);
  • Init(&sommet);
  • Traitement(ch);
  • getch();
  • }
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>


struct ma_pile{
	       char info;
	       struct ma_pile *suiv;
	      };

/****************** declaration Variables globales *****************/

struct ma_pile *sommet;
char p1;
char ch[20],c;
int i=0,code=0;
char tempo[2];

/****************** ce qui suit est des fonctions *********************/


struct ma_pile *Init(struct ma_pile **sommet)
{
 *sommet=NULL;
 return *sommet;
}


int char_to_int(char c)
 {
  if(c=='0')
   return code==0;
  else
   {
    code=c-48;
    return code;
   }
 }


char int_to_char(int int_to_ch)
{
 int_to_ch+=48;
 c=(char)int_to_ch;    // converti l'ascii int_to_char en caractere
 return c;
}


void EMP(char x,struct ma_pile **sommet)
{
 struct ma_pile *p;

   p=(struct ma_pile *)malloc(sizeof(struct ma_pile));
   p->info=x;
   p->suiv=*sommet;
   *sommet=p;
}


int DEP(struct ma_pile **sommet)
{
  if(*sommet==NULL)
   printf("E R R E U R ! LA PILE EST VIDE");
  else
   {
    struct ma_pile *p=*sommet;
    p1=p->info;
    *sommet=p->suiv;
    free(p);
    printf("\nOPERATION SUCCESS\n");
    printf("VALEUR DEPILEE :%d\n",char_to_int(p1));
    return p1;
   }

}


void saisie(char t[1])
{
   char c;
   int j1=0;

   do
    {
     c=getch();
     if(((c>='0')&& (c<='9')) || ((c=='*')|| (c=='-')|| (c=='+')|| (c=='/')))
      {
       if((c>='0')&& (c<='9'))
	{
	  j1++;     //comptabilise les caracteres entre '0' et '9'
	  if(j1>2)
	   printf("ACTION NON AUTORISEE\n");
	  else
	  {
	   t[i]=c;
	   printf("%c\n",t[i]);
	   i++;
	  }
	}

       if((c=='*')|| (c=='-')|| (c=='+')|| (c=='/'))
	 {
	   j1=0;
	   t[i]=c;
	   printf("%c\n",t[i]);
	   i++;

	 }
      }
    }
   while(c!=13);
}

void VISU(struct ma_pile *sommet)
{
  if(sommet!=NULL)
   {
    struct ma_pile *p=sommet;

    while(p) {
    printf("%c ->",p->info);
    p=p->suiv; }
   }
  else
   printf("E R R E U R ! VEUILLEZ D'ABORD REMPLIR LA PILE ");
}


void Traitement(char t[1])
{
  int k,k1,code2=0,code1=0,resultat=0;

  char c;
   for(k=0;k<i;k++)
     {
      if ((t[k]>='0') &&(t[k]<='9'))
       EMP(t[k],&sommet);

      if((t[k]=='*')|| (t[k]=='-')|| (t[k]=='+')|| (t[k]=='/'))
       {k1=1;      //on commence … d‚piler

	while((sommet!=NULL) && (k1>=0))  //ne depile que les 2 1ere valeurs
	 {
	  DEP(&sommet);
	  tempo[k1]=p1;
	  k1--;
	 }
	code1=char_to_int(tempo[0]);
	code2=char_to_int(tempo[1]);

       switch (t[k])
	{
	 case '+':resultat=code1+code2;printf("%d+%d=%d\n",code1,code2,resultat);
		  break;
	 case '-':resultat=code1-code2;printf("%d-%d=%d\n",code1,code2,resultat);
		  break;
	 case '*':resultat=code1*code2;printf("%d*%d=%d\n",code1,code2,resultat);
		  break;
	 case '/':resultat=code1/code2;printf("%d/%d=%d   il s'agit d'une division entiŠre\n",code1,code2,resultat);
		  break;
	}

	 EMP(int_to_char(resultat),&sommet);

       }

     }

}




/***********************
Fin des fonctions **********/


/*********************** 
Ceci est mon programme****/

void main()
{
 clrscr();
 saisie(ch);
 Init(&sommet);
 Traitement(ch);
 getch();
}

Conclusion

pour toutes suggestions ou remarques,veuillez me contactez
  • signaler à un administrateur
    Commentaire de Joky le 09/01/2005 17:04:52

    Et pk on apelle ça Notation Polonaise ???

  • signaler à un administrateur
    Commentaire de Kirua le 10/01/2005 17:46:37

    je sais pas pq polonaise (pê que c'est une notation privilégiée par les polonais ^^), mais on appelle souvent la notation polonaise inverse la "postfix" et la notation "naturelle" (pour nous) la infix (en anglais, parce qu'en français on dit suffixé et infixé)

  • signaler à un administrateur
    Commentaire de Stepharcher le 27/01/2005 22:07:26

    quelle culture ! :p

  • signaler à un administrateur
    Commentaire de freddy1787 le 25/10/2007 17:57:05

    Parceque c'est un polonais qui l'a invente !!

Ajouter un commentaire

Pub



Appels d'offres

Plugin Dialer outlook
Budget : 2 000€
Travail graphique- ill...
Budget : 1 000€
creation de marque et ...
Budget : 1 000€

CalendriCode

Juillet 2008
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Boutique

Boutique de goodies CodeS-SourceS