implementing stack using two queues
initially q1 is full and q2 empty
1] transfer elements from q1 to q2 till last element left in q1
2] loop till q2 is not empty
deque element from q2 and again push in q2 till last element is left in q2
transfer this last element in q1
reduce size of q2 by 1
3]finally q1 contains all elements in reverse order as in stack
eg
1]
q1 = 1 2 3 4
q2 =
2]
3 deques till last element left in q1
q1 = 4
q2 = 1 2 3
3]
deque and again queue q2 till last element left
q1 = 4
q2 = 3 1 2
4] deque q2 and queue q1
q1 = 4 3
q2 = 1 2
5] again
deque and queue q2 till last element left
q1= 4 3
q2= 2 1
6] queue q1
q1= 4 3 2
7] queue last element of q2 to q1
q1= 4 3 2 1
No. A stack is a data structure that allows insertion and removal at the top. A circular list allows insertion and removal anywhere in the list. The two types of data structure are too different to be reasonably implementable in terms of each other.
queue is an abstract data type that which entities in a collection are kept in order, this makes the sense of fifo(first in first out). stack is a container of the object which works on the principle of lifo(last in first out)
Two little problems: 1. stack doesn't have a flow-chart 2. there are no flow-charts in a C program
You can determine symmetry of a data structure in two ways. One is when the stacks and queues data are put in the application and when the stacks are put in during run-time.
To convert a stack into a queue, you can use two stacks. First, pop all elements from the original stack and push them onto the second stack. Then, to dequeue an element, simply pop from the second stack. This method allows you to maintain the queue's FIFO (first-in, first-out) property while using the LIFO (last-in, first-out) nature of stacks.
To implement a queue using stacks efficiently, you can use two stacks. One stack is used for enqueueing elements, and the other stack is used for dequeueing elements. When dequeueing, if the dequeue stack is empty, you can transfer elements from the enqueue stack to the dequeue stack to maintain the order of elements. This approach allows for efficient implementation of a queue using stacks.
There is no inherent relationship between the two. It's possible to implement a stack using an array to store date, but that's about it.
No. A stack is a data structure that allows insertion and removal at the top. A circular list allows insertion and removal anywhere in the list. The two types of data structure are too different to be reasonably implementable in terms of each other.
queue is an abstract data type that which entities in a collection are kept in order, this makes the sense of fifo(first in first out). stack is a container of the object which works on the principle of lifo(last in first out)
Two possible solutions: 1. Separated queue for every possible priority value. 2. One shared queue for every elements, sorted by priority.
we can do sorting by using two interfaces like comparator and comparable
Two little problems: 1. stack doesn't have a flow-chart 2. there are no flow-charts in a C program
identification and authentication
identification and authentication
You can determine symmetry of a data structure in two ways. One is when the stacks and queues data are put in the application and when the stacks are put in during run-time.
This is not possible as this violates the basic definition of stack...That can have only two primitive operations "Push" "POP" If u want to implement what u want u can do that by some implementation of Push pop combination but that is what other data strutures like queue do....
To exchange two registers, say the BX and CX registers, in the 8086 using the stack, you can use...PUSH BXPUSH CXPOP BXPOP CX... Of course, this is for 16 bit operation. If you want 8 bit operation, you will need to do more than that, because stack operations are always 16-bit operations.