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

Explain how do I determine whether a character is numeric, alphabetic, and so on?

642


How do I send escape sequences to control a terminal or other device?

600


Where is c used?

641


What is difference between array and structure in c?

565


code for quick sort?

1605






what is the diffrenet bettwen HTTP and internet protocol

1377


What are nested functions in c?

555


How to Throw some light on the splay trees?

611


What is signed and unsigned?

629


Can we replace the struct function in tree syntax with a union?

765


What are local static variables? How can you use them?

635


What are the different data types in C?

716


Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.

818


How many data structures are there in c?

603


Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?

554