0% found this document useful (0 votes)
37 views5 pages

Design Problem-2 OF CSE-368

This document appears to be a design problem submission for a data structures course. It includes source code for an infix to postfix conversion program using a stack. The code defines functions for pushing and popping from the stack, showing the stack contents, and checking if the stack is empty or full. It also includes a main function that takes an infix expression as input, converts it to postfix by processing the expression and handling operator precedence, and prints the output.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views5 pages

Design Problem-2 OF CSE-368

This document appears to be a design problem submission for a data structures course. It includes source code for an infix to postfix conversion program using a stack. The code defines functions for pushing and popping from the stack, showing the stack contents, and checking if the stack is empty or full. It also includes a main function that takes an infix expression as input, converts it to postfix by processing the expression and handling operator precedence, and prints the output.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

DESIGN PROBLEM-2

OF
CSE-368

Submittedto: Submitted by:

Ms. Navdeep kaur sandhu Abhishek Kumar

B.tech (H)-CSE

Section:-A1810

Roll. No. 16
#include <stdio.h>

#define size 10

char stack[size];

int tos=0,ele;

void push();

char pop();

void show();

int isempty();

int isfull();

char infix[30],output[30];

int prec(char);

int main()

int i=0,j=0,k=0,length;

char temp;

printf("\nEnter an infix expression:");

scanf("%s",infix);

printf("\nThe infix expresson is %s",infix);

length=strlen(infix);

for(i=0;i<= prec(stack[tos-1]) )

temp=pop();

printf("\n the poped element is :%c",temp);

output[j++]=temp;

push(infix[i]);

printf("\n The pushed element is :%c",infix[i]);

show();
}

else

push(infix[i]);

printf("\nThe pushed element is:%c",infix[i]);

show();

else

if(infix[i]=='(')

push(infix[i]);

printf("\nThe pushed-- element is:%c",infix[i]);

if(infix[i]==')')

temp=pop();

while(temp!='(')

{output[j++]=temp;

printf("\nThe element added to Q is:%c",temp);

//temp=pop();

printf("\n the poped element is :%c",temp);

temp=pop();}

}
}

printf("\nthe infix expression is: %s",output);

while(tos!=0)

output[j++]=pop();

printf("the infix expression is: %s\n",output);

//Functions for operations on stack

void push(int ele)

stack[tos]=ele;

tos++;

char pop()

tos--;

return(stack[tos]);

void show()

int x=tos;

printf("--The Stack elements are.....");

while(x!=0)

printf("%c, ",stack[--x]);

}
//Function to get the precedence of an operator

int prec(char symbol)

if(symbol== '(')

return 0;

if(symbol== ')')

return 0;

if(symbol=='+' || symbol=='-')

return 1;

if(symbol=='*' || symbol=='/')

return 2;

if(symbol=='^')

return 3;

return 0;

You might also like