void evalpo(stack *s) { printf("\n Enter the postfix expression : "); scanf(" %s",a); int len=strlen(a); printf("\n Length of above expression is : %d \n",len); for(i=0; i<len ; i++) { if(check(a[i])==0) //meaning its an operand { pushe(s,a[i]-48); } if(check(a[i])==1) //meaning its an operator { printf("\n Popping the top two \n"); p1=pope(s); p2=pope(s); p0=op(p2,p1,a[i]); //top ke neeche waala ka operation with top pushe(s,p0); } } printf("\n Evaluating postfix exp = %d \n",s->st[s->top]); options(s); }
void main(int argc, char *argv[]) { int i; node_t * head = NULL; node_t * heao = NULL; head = malloc(sizeof(node_t)); heao = malloc(sizeof(node_t)); head->val = 0; heao->val = 9; head->next=NULL; heao->next=NULL; head->id=0; heao->id=0; for(i=1; i< //PAL_SIZE 7 ; i++) { if(!(i%3)) printf("\n "); printf("%d,", i); pushe(head, i); } printf("\n"); for(i=8; i>0; i--) { if(!(i%3)) printf("\n "); printf("%d,", i); pushe(heao, i); } print_list(head); printf("\n"); print_list(heao); free(head); free(heao); }
void evalpre(stack *s) { printf("\n Enter the prefix expression : "); scanf(" %s",a); int len=strlen(a); printf("\n Length of above expression is : %d \n",len); for(i=len-1; i>=0 ; i--) { if(check(a[i])==0) //meaning its an operand { pushe(s,a[i]-48); } if(check(a[i])==1) //meaning its an operator { printf("\n Popping the top two \n"); p1=pope(s); p2=pope(s); p0=op(p1,p2,a[i]); //top ka top ke neeche waale se operation pushe(s,p0); } } printf("\n Evaluating prefix exp = %d \n",s->st[s->top]); options(s); }
void main() { char c; char a[30]; do { clrscr(); printf("1.ENTER 1 TO PUSH ELEMENT TO THE STACK\n"); printf("2.ENTER 2 TO POP THE ELEMENT FROM THE STACK\n"); printf("3.ENTER 3 TO DISPLAY THE ELEMENTS OF THE STACK\n"); printf("4.enter 4 to add element at the end\n"); printf("5.enter 5 to enter element after specified position/n"); printf("enter your choice : "); scanf("%c",&c); switch(c) { case '1':printf("enter the element to be pushed "); fflush(stdin); gets(a); push(a); break; case '2':pop();getch();break; case '3':dis();getch();break; case '4':printf("enter the element to be pushed "); fflush(stdin); gets(a); pushe(a); break; } }while(c!='0'); }