Write a nonrecursive routine to reverse a singly linked
list in O(N) time.
Answer Posted / hasan ali mirza
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int preceed(char c);
void push(char c);
char pop();
char stk[30];
int tos=-1;
int main()
{
int i,j=0,n,u,v;
char infix[30],postfix[30],c;
printf("Enter the infix expression:");
scanf("%s",&infix);
n=strlen(infix);
for(i=0;i<n;i++)
{
if((infix[i]>='a'&&infix[i]<='z')||(infix[i]>='A'&&infix[i]<='Z'))
{
postfix[j]=infix[i];
j++;
}
else if(infix[i]=='^'||infix[i]=='*'||infix[i]=='/'||infix[i]=='+'||infix[i]=='-')
{
u=preceed(stk[tos]);
v=preceed(infix[i]);
while(u>=v&&stk[tos]!='(')
{
postfix[j]=pop();
j++;
u=preceed(stk[tos]);
}
push(infix[i]);
}
else if(infix[i]=='(')
{
push(infix[i]);
}
else if(infix[i]==')')
{
c=pop();
while(c!='(')
{
postfix[j]=c;
j++;
c=pop();
}
}
else
{
printf("Equation has error\n");
exit(0);
}
}
while(tos!=-1)
{
postfix[j]=pop();
j++;
}
postfix[j]=='\0';
printf("The equation in postfix:%s",postfix);
}
void push(char c)
{
tos++;
stk[tos]=c;
}
char pop()
{
char val;
val=stk[tos];
tos--;
return(val);
}
int preceed(char c)
{
int v;
switch(c)
{
case '^':v=3;
break;
case '*':
case '/':v=2;
break;
case '+':
case '-':v=1;
break;
default:v=0;
break;
}
return(v);
}
| Is This Answer Correct ? | 2 Yes | 2 No |
Post New Answer View All Answers
Draw the diagram showing the function stack, illustrating the variables that were pushed on the stack at the point when function f2 has been introduced . type def struct { double x,double y} point; } main( int argc, char *arg[3]) { double a; int b,c; f1(a,b); } f1(double x, int y) {point p; stack int n; f2(p,x,y) } f2(point p, double angle) { int i,j,k,int max;
What is frog testing? What is cone model?
there are 50 users in a network, one system is virus affected , how to find that virus affected system?
if a customer's blackberry stopped syncing their calendar wirelessly what would you do?if a customber deleted mail from his blackberry but it did delete from his mailbox how would ypu resolve this
hi friends.... i want do telecom course, iam getting confused. plz tell me courses and levels in that field. iam fresher B.E ECE student. and plz tell institutes in hydrabad or bangalure.
what is the differences between DTD's and XML schema?
Tell me about your parents?? Pls share any one best words...
what is advantages and disadvantages of CAT5,CAT5e,CAT6,CAT7,COAXIAL CABLE,FIBER-OPTIC
In HSE what is Lost time accident? why it is to be reported within 48 hrs to gov.authorities ?
what is overflow and what are the conditions for which overflow possible?
compair and contrast procedrual and object oriented programming language
what in 4th and 5th normal form ??
I want to prepare for PSU's bt i dont know how many PSU's are open for computer science students and what is the competition level for these. So if anybody knows this please guide me through this.
what is debugging?
hello sir, i'm persuing my B.tech final year in textile chemistry and have a diploma in electronics and communication...interviewer ask why you should adopt textile chemistry from electronics and communication....please give me the best answer... thank you