c code to java converter
#include <stdio.h>
c code to java converter
#include <cstdlib>
#include <algorithm>
#include "stdio.h"
#include "stdlib.h"
#define Pila_vacia (pila == NULL)
using namespace std;
typedef struct datos elemento;
struct datos {
char dato;
elemento *anterior;
};
void error(void) {
perror("\n\a Error: Memoria insuficiente..");
exit(1);
}
elemento *Nuevo() {
elemento *q = (elemento *) malloc(sizeof (elemento));
if (!q) error();
return (q);
}
void push(elemento **p, char x) {
elemento *q, *tope;
tope = *p;
q = Nuevo();
q->dato = x;
q->anterior = tope;
tope = q;
*p = tope;
}
char pop(elemento **p) {
elemento *tope;
char x;
tope = *p;
if (tope == NULL) {
printf("\n\a\t ERROR: POP= pila Vacia...\n");
return ('0');
}
x = tope->dato;
*p = tope->anterior;
free(tope);
return (x);
}
void lee(char ent[]) {
int pos = 0;
printf("\n\n\tEntra la expresion Infija:");
while ((ent[pos++] = getchar()) != '\n');
ent[--pos] = '\0';
}
int verifica(char ent[]) {
elemento *pila = NULL;
int valido, pos = 0;
char op, a;
valido = 1;
while (ent[pos] != '\0') {
op = ent[pos++];
if (op == '(' || op = '{' || op == '[') push(&pila, op);
if (op == ')' || op = '}' || op == ']') {
if (Pila_vacia) valido = 0;
else {
a = pop(&pila);
if (op == ')' && a != '(') valido = 0;
if (op == '}' && a != '{') valido = 0;
if (op == ']' && a != '[') valido = 0;}}}
if (!Pila_vacia) valido = 0;
return (valido);}
int main(int argc, char** argv) {
char ent[100];
printf("Verificador de Delimitadores.");
printf("Verifica los simbolos: (), [], {}");
printf("en una expresion infija.");
lee(ent);
if (verifica(ent))printf("Cadena Valida.");
else printf("Cadena Invalida.");
return 0;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us