Consider a language that does not have arrays but does have
stacks as a data type.and PUSH POP..are all defined .Show
how a one dimensional array can be implemented by using two
stacks.
Answer Posted / abdur rab
The arrays are always sequential, since we are going to use
stack, ther is no possibility for random access.
PUSH all the values in the stack1, then pop the value from
stack1 into stack2.
so whenever ther is a PUSH to stack1, we need to POP all
the elements from stack2 to stack1 and then PUSH the new
value. Now POP all the values from stack1 to stack2. It ud
work like a queue then.
| Is This Answer Correct ? | 4 Yes | 3 No |
Post New Answer View All Answers
Explain Basic concepts of C language?
Explain what is the difference between #include and #include 'file' ?
There seem to be a few missing operators ..
How do I create a directory? How do I remove a directory (and its contents)?
#include main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf(" %d",*p); *p = 10; printf(" %d %d",i,*p); c = (int*) calloc(2); printf(" %d ",*c); }
What is a char c?
Differentiate between full, complete & perfect binary trees.
Why can’t constant values be used to define an array’s initial size?
How do you print an address?
What is the purpose of macro in C language?
Can you write a programmer for FACTORIAL using recursion?
What is function prototype?
What are pointers? What are stacks and queues?
Why c is a mother language?
What are the 4 types of programming language?