Beruflich Dokumente
Kultur Dokumente
ASSIGNMENT – 2
Data Structures
Ans1:-
Circular queue whose total size is 11, front and rear pointers are initialized to point at
q[2]:
Ans 2.
int main()
{
char prefix[20];
char postfix[20];
printf("\n\n Enter the prefix expression \n\n");
scanf("%s",prefix);
pre_post(prefix,postfix);
printf("\n\n The postfix expression is %s \n\n",postfix);
return 0;
}
3. Write a algorithm which gives solution to Towers of Hanoi Problem
for n disks. Test the algorithm using n =3.
Ans 3.
1. Tower(n,beg,aux,end)
2. If n==1
(a)beg->end
(b)return
End of if statement
3. Move n-1 disk from reg beg to reg aux
Call tower(n-1,beg,end,aux)
4. Beg->end
5. Move n-1 disk from reg aux to reg end
Call tower(n-1,aux ,beg,end)
6. return