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 a class?

3 Answers  


How do you print only part of a string?

0 Answers  


What is an array in c?

0 Answers  


c program to print a name without using semicolon

9 Answers   TCS, Wipro,


#include<stdio.h> main() { int i=5; printf("%d",i*i-- - --i*i*i++ + ++i); } tell the answer with correct reason .specially reason is important nt answer ans by turbo c is -39

1 Answers   GameLoft,






Explain how can I pad a string to a known length?

0 Answers  


What is assert and when would I use it?

0 Answers  


Can you write a programmer for FACTORIAL using recursion?

0 Answers   ADP,


what is uses of .net

0 Answers  


What does static variable mean in c?

0 Answers  


An arrangement of information in memory in such a way that it can be easily accessed and processed by a programming language a) string b) data structure c) pointers d) array

0 Answers  


What are the salient features of c languages?

0 Answers  


Categories