Índice de regreso de una matriz!

  • whitey300
  • Born
  • Born
  • No Avatar
  • Registrado: Oct 22, 2009
  • Mensajes: 2
  • Status: Offline

Nota Octubre 22nd, 2009, 6:19 pm

Estoy teniendo problemas para encontrar la manera de devolver el índice de un elemento de una matriz o una cadena. Mi programa es un ejemplo de un árbol de expresión en un niño de izquierda matriz hijo derecho. El usuario introduce una expresión como x 2 y salida Shaud como sigue:

+ 1 2
2 0 0
x 0 0

El 1 en la columna 2 ª representa la fila del niño y la izquierda está en la 2 en la columna 3 representa la fila del niño es el derecho in Otro ejemplo sería + / 43 * 34

+ 1 4
/ 2 3
4 0 0
3 0 0
* 5 6
3 0 0
4 0 0

este es mi código hasta ahora:
Código: [ Select ]

#include <iostream>
#include <iomanip>

using namespace std;


int main()
{
  char s[50];
  cout << "Input the prefix expression.\n";
  cin >> s;
  cout << "\nThe expression tree is:";

 
  int row = strlen(s);
  int col = 2;
  char a[9][4];
  int i, j, c;
  int index = 1;
 
  for (j = 0; j < row; j++)
  {
    a[j][0] = s[j];

  for(i = 1; i <= col; i++)
  {
  
   
    if ( s[j] == '+' || s[j] == '-' || s[j] == '*' || s[j] == '/')
    {
      a[0][i] = index;
    }
    else
    {
      a[j][i] = '0';
    }
    index++;
  }
  }

  for (j = 0; j < row; j++)
  {
    cout << "\n";
  for(i = 0; i <= col; i++)
  {
    cout << a[j][i] << setw(2);

  }
  }

  cout << "\n\nThe postfix expression is " << endl;
 
  cout << "The infix expression is " << endl;
 
  system ("PAUSE");
  return 0;
}
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4. int main()
  5. {
  6.   char s[50];
  7.   cout << "Input the prefix expression.\n";
  8.   cin >> s;
  9.   cout << "\nThe expression tree is:";
  10.  
  11.   int row = strlen(s);
  12.   int col = 2;
  13.   char a[9][4];
  14.   int i, j, c;
  15.   int index = 1;
  16.  
  17.   for (j = 0; j < row; j++)
  18.   {
  19.     a[j][0] = s[j];
  20.   for(i = 1; i <= col; i++)
  21.   {
  22.   
  23.    
  24.     if ( s[j] == '+' || s[j] == '-' || s[j] == '*' || s[j] == '/')
  25.     {
  26.       a[0][i] = index;
  27.     }
  28.     else
  29.     {
  30.       a[j][i] = '0';
  31.     }
  32.     index++;
  33.   }
  34.   }
  35.   for (j = 0; j < row; j++)
  36.   {
  37.     cout << "\n";
  38.   for(i = 0; i <= col; i++)
  39.   {
  40.     cout << a[j][i] << setw(2);
  41.   }
  42.   }
  43.   cout << "\n\nThe postfix expression is " << endl;
  44.  
  45.   cout << "The infix expression is " << endl;
  46.  
  47.   system ("PAUSE");
  48.   return 0;
  49. }
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Octubre 22nd, 2009, 6:19 pm

  • whitey300
  • Born
  • Born
  • No Avatar
  • Registrado: Oct 22, 2009
  • Mensajes: 2
  • Status: Offline

Nota Octubre 22nd, 2009, 7:46 pm

¿Puede alguien ayudarme por favor!!!

Publicar Información

  • Total de mensajes en este tema: 2 mensajes
  • Usuarios navegando por este Foro: ScottG y 277 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC