Answers for "c code to java converter"

0

c code to java converter

#include <stdio.h>
Posted by: Guest on March-04-2021
0

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;
}
Posted by: Antony Tenorio on March-20-2022

Code answers related to "c code to java converter"

Browse Popular Code Answers by Language