Write a nonrecursive routine to reverse a singly linked
list in O(N) time.

Answers were Sorted based on User's Feedback



Write a nonrecursive routine to reverse a singly linked list in O(N) time...

Answer / sandeep

node * reverse(node * list)
{
node *p, *q, *r;
p = list;
q = p->next;
while(q->next != NULL)
{
q = p->next;
r = q->next;
p->next = r;
q->next = p;
p = p->next;
}
q->next = p;
p->next = NULL;
return q`;
}

Is This Answer Correct ?    26 Yes 7 No

Write a nonrecursive routine to reverse a singly linked list in O(N) time...

Answer / mahesh

refer to the page number 456 in ds by sahani

Is This Answer Correct ?    10 Yes 8 No

Write a nonrecursive routine to reverse a singly linked list in O(N) time...

Answer / hasan ali mirza

list reverse(list L)
{
stack S;
position Lpos = first(L);
while(Lpos->element != NULL)
{
push(Lpos->element, S);
Lpos = Lpos->next;
}
makeEmpty(L);
Lpos = first(L);
while(isempty(S) == FALSE)
{
insert(pop(S), Lpos);
Lpos = Lpos->next;
}
return L;
}

Is This Answer Correct ?    3 Yes 1 No

Write a nonrecursive routine to reverse a singly linked list in O(N) time...

Answer / 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

More Engineering AllOther Interview Questions

I am 2012 pass out b tech student(cse). i have recently started software manual testing class. Is this field is benefitial for me in future?

0 Answers  


how many clusters are generated by k-means algorithm?

0 Answers  


How is the parity flag actually set in the 8085 microprocessor?

0 Answers  


how to identify analog and digital in instrumentation

1 Answers   GS Engineering Construction,


is the RKDF university is aicte approved for b.tech in computer

0 Answers  


Guys! I coplted 10th with 80% and +2 with 64% now am dng c.s.e b.tech...i want to go abroad for higher studies i want to write tofel...plZ GIVE UR SUGGESTIONS!

0 Answers  


What are the frequently asked technical engineer ques?

0 Answers  


main() { int a=10,b; b=a>=5?100:200; printf("%d\n",b); }

1 Answers   Vector,


what is polymorphism?

1 Answers  


defference between menu and context menu in vb.net?

0 Answers  


what is polymorphism.

0 Answers  


#include<stdio.h> int main(){ int a=5; printf("%d %d %d",a++,a++,++a); return 0; }..please explain me output 7 6 8..Thnx in advance

1 Answers  


Categories
  • Civil Engineering Interview Questions Civil Engineering (5085)
  • Mechanical Engineering Interview Questions Mechanical Engineering (4453)
  • Electrical Engineering Interview Questions Electrical Engineering (16637)
  • Electronics Communications Interview Questions Electronics Communications (3918)
  • Chemical Engineering Interview Questions Chemical Engineering (1095)
  • Aeronautical Engineering Interview Questions Aeronautical Engineering (239)
  • Bio Engineering Interview Questions Bio Engineering (96)
  • Metallurgy Interview Questions Metallurgy (361)
  • Industrial Engineering Interview Questions Industrial Engineering (259)
  • Instrumentation Interview Questions Instrumentation (3014)
  • Automobile Engineering Interview Questions Automobile Engineering (332)
  • Mechatronics Engineering Interview Questions Mechatronics Engineering (97)
  • Marine Engineering Interview Questions Marine Engineering (124)
  • Power Plant Engineering Interview Questions Power Plant Engineering (172)
  • Textile Engineering Interview Questions Textile Engineering (575)
  • Production Engineering Interview Questions Production Engineering (25)
  • Satellite Systems Engineering Interview Questions Satellite Systems Engineering (106)
  • Engineering AllOther Interview Questions Engineering AllOther (1379)