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



Consider a language that does not have arrays but does have stacks as a data type.and PUSH POP..are..

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

Consider a language that does not have arrays but does have stacks as a data type.and PUSH POP..are..

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

Consider a language that does not have arrays but does have stacks as a data type.and PUSH POP..are..

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

Post New Answer

More C Interview Questions

What is memory leak in c?

0 Answers  


int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;

0 Answers  


Which is better oop or procedural?

0 Answers  


dibakar & vekatesh..uttejana here..abt ur reply for in place reversal of linked list..wats p stands for there?

1 Answers  


Write a program to print distinct words in an input along with their count in input in decreasing order of their count..

1 Answers  






what are the compilation steps? ( i want inside the compiler )

2 Answers  


What is wrong with this program statement? void = 10;

0 Answers  


What is the hardest programming language?

0 Answers  


String concatenation

2 Answers  


i have to apply for rbi before that i need to know the the syllabus for the entrance questions. whethet it may be aps or techinical

0 Answers  


What is structure padding and packing in c?

0 Answers  


what is the purpose of the code, and is there any problem with the code? int f( int n, int l, int r ) { return (n << l) >> r; }

2 Answers   Google,


Categories