Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- struct EST_PILHA{
- int TOPO;
- int INFO[1000];
- };
- struct EST_PILHA Cria (void)
- {
- struct EST_PILHA P;
- P.TOPO = -1;
- return P;
- }
- int PilhaVazia(struct EST_PILHA P)
- {
- //Retorna 1 se a pilha estiver vazia, caso contrário retorna 0;
- if(P.TOPO == -1)
- return 0;
- else
- return 1;
- }
- int QuantidadePilha(struct EST_PILHA P)
- {
- return P.TOPO + 1;
- }
- void POP(struct EST_PILHA *P)
- {
- int Valor = 0;
- Valor = (*P).INFO [(*P).TOPO];
- (*P).TOPO--;
- }
- struct EST_PILHA PUSH(int Vlr, struct EST_PILHA P)
- {
- P.TOPO++;
- P.INFO[P.TOPO] = Vlr;
- return P;
- }
- void iguala(EST_PILHA *P){
- if((*P).TOPO>-1){
- while((*P).TOPO>-1){
- int Valor = 0;
- Valor = (*P).INFO [(*P).TOPO];
- (*P).TOPO--;
- }
- }
- }
- int main(int argc, char** argv)
- {
- char exp[1001];
- int i,vlr;
- struct EST_PILHA Pilha;
- bool boo=true;
- Pilha = Cria();
- while(scanf("%s",&exp) != EOF){
- i=0;
- vlr=1;
- boo=true;
- printf("%d", Pilha.TOPO);
- iguala(&Pilha);
- printf("%d", Pilha.TOPO);
- if(Pilha.TOPO==-1){
- while(exp[i]!='\0' && boo==true){
- if(exp[i]=='('){
- vlr=1;
- Pilha=PUSH(vlr,Pilha);
- }
- else if(exp[i]==')')
- {
- POP(&Pilha);
- if(Pilha.TOPO==-2){
- boo=false;
- Pilha=PUSH(vlr,Pilha);
- }
- }
- i++;
- }
- }
- if(Pilha.TOPO==-1 && boo==true){
- printf("correct\n");
- }
- else if(Pilha.TOPO!=-1){
- printf("incorrect\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement