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


Please Help Members By Posting Answers For Below Questions

What is selection sort in c?

797


Between macros and functions,which is better to use and why?

1794


Write a code to generate divisors of an integer?

810


What is the use of a conditional inclusion statement in C?

821


the constant value in the case label is followed by a a) semicolon b) colon c) braces d) none of the above

993


What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.

3958


any "C" function by default returns an a) int value b) float value c) char value d) a & b

855


How do shell structures work?

782


What is ctrl c called?

778


What is the purpose of sprintf?

814


c language supports bitwise operations, why a) 'c' language is system oriented b) 'c' language is problem oriented c) 'c' language is middle level language d) all the above

810


Why cant I open a file by its explicit path?

802


Which header file is essential for using strcmp function?

1167


What is c language in simple words?

808


What is difference between structure and union?

844