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.
Answers were Sorted based on User's Feedback
Answer / barun
In one stack keep values and in another stack keep index of
array. In other wards a[0] = 10. Then keep in bottom of
stack1 value 10 and in bottom of stack2 0. Both needs to be
synchronized in such implementation. Of course random access
is not possible.
| Is This Answer Correct ? | 6 Yes | 2 No |
Answer / gingercpu
One to pop and the other to push. Have to maintain all the
elements. Index converted to the # of push and pop
| Is This Answer Correct ? | 4 Yes | 2 No |
Answer / 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 |
What is action and transformation in spark?
When I tried to go into a security sites I am denied access and a message appeared saying 'applet not initialize'. How can I rectify this problem.
Explain what is a static function?
When can you use a pointer with a function?
what is the use of ‘auto’ keyword?
int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give me the explanation.
Why data types in all programming languages have some range? Why ritche have disigned first time likethat?Why not a single data type can support all other types?
array of pointer pointer to array pointer to pointer
How do I create a directory? How do I remove a directory (and its contents)?
Can true be a variable name in c?
WHAT WILL BE OUTPUT OF BELOW CODE . . AND PLEASE EXPLAIN HOW IT COME .. #include<stdio.h> #include<conio.h> void main() { int k=20; printf("%d%d%d%d",k,k++,++k,k); getch(); }
what is the difference between. system call and library function?