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 the size of a union variable?

0 Answers  


What is the use of header files?

0 Answers  


What are keywords in c with examples?

0 Answers  


Explain what is wrong with this program statement? Void = 10;

0 Answers  


A program to write a number of letters and numbers, such as counting and display

0 Answers  






How macro execution is faster than function ?

0 Answers   Wipro,


Write a c program to sort six numbers and find the largest one by using the ladder of if-else? plz do help me

2 Answers  


why do some people write if(0 == x) instead of if(x == 0)?

0 Answers  


Code for calculating square root without using library function, of math.h

4 Answers   IBM,


how to estimate the disk access time? e.g. the time between read one byte and another byte in the disk.

3 Answers   Google,


how to find out the biggest element (or any other operation) in an array which is dynamic. User need not to mention the array size while executing.

3 Answers  


1.)how to find d most repeated word in a string? string ="how do you do"?? output should be do

1 Answers   AAS, Nagarro, Vuram,


Categories