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
How can write a C program that shows All the prime number?
what is different between static block and public static void main??
Hii can you help me step by step procedure for transfering data in textfields into sql database .mdf(also help me how to create database .mdf file) file after creating submit button in asp.net/ c#?????
i need to know abt renault nissan company and the rounds and type of questions asked by today
Is there aptitute question will be asked in NIC exam ??? If yes how many questions will be asked??
how many protocols are available and what are they?
Why is not creat swap partition in my system.
I am looking for NIC Scientific Officer / Engineer-SB (Programmer)Sample papers or any portion of questions/ syllabus plz, send me on sengupta.pranab@gmail.com. Regards PRANAB
i am shortlisted in corporation bank for the post of computer officer the next phase is group discussion. i want to know how to prepare and what about the topics for preparing thanking you if you have any suggestion please give me prabhatmishra21@rediffmail.com
What is The Need of Template?
what is the quantity of cement and sand in 1 sq.m (mortar ratio ) a, 1:4 b, 1:3 c, 1:6
what is the difference b/w "print" and "sprint" in sql?
Can you connect Active Directory to other 3rd-party Directory Services? Name a few options.
what is the program to find out the smallest word in a sentence? like if the sentence is : this is my room. then out put will be : is
What is Moore's law and what limits the size of a computer chip?