title
4.6 Implement Queue using Stack in C| Data Structures Tutorials

description
Discussed how to implement queue using stacks with example. I have written a C program for implementation of queue using stacks DSA Full Course: https: https://www.youtube.com/playlist?list=PLdo5W4Nhv31bbKJzrsKfMpo_grxuLl8LU ****************************************** See Complete Playlists: C Programming Course: https://www.youtube.com/playlist?list=PLdo5W4Nhv31a8UcMN9-35ghv8qyFWD9_S C++ Programming: https://www.youtube.com/playlist?list=PLdo5W4Nhv31YU5Wx1dopka58teWP9aCee Python Full Course: https://www.youtube.com/playlist?list=PLdo5W4Nhv31bZSiqiOL5ta39vSnBxpOPT Printing Pattern in C: https://www.youtube.com/playlist?list=PLdo5W4Nhv31Yu1igxTE2x0aeShbKtVcCy DAA Course: https://www.youtube.com/playlist?list=PLdo5W4Nhv31ZTn2P9vF02bkb3SC8uiUUn Placement Series: https://www.youtube.com/playlist?list=PLdo5W4Nhv31YvlDpJhvOYbM9Ap8UypgEy Dynamic Programming: https://www.youtube.com/playlist?list=PLdo5W4Nhv31aBrJE1WS4MR9LRfbmZrAQu Operating Systems: //www.youtube.com/playlist?list=PLdo5W4Nhv31a5ucW_S1K3-x6ztBRD-PNa DBMS: https://www.youtube.com/playlist?list=PLdo5W4Nhv31b33kF46f9aFjoJPOkdlsRc ****************************************** Connect & Contact Me: Facebook: https://www.facebook.com/Jennys-Lectures-CSIT-Netjrf-316814368950701/ Quora: https://www.quora.com/profile/Jayanti-Khatri-Lamba Instagram: https://www.instagram.com/jayantikhatrilamba/ #jennyslectures #datastructures #queue #ugcnet #computerscience #course

detail
{'title': '4.6 Implement Queue using Stack in C| Data Structures Tutorials', 'heatmap': [{'end': 368.448, 'start': 347.828, 'weight': 0.702}, {'end': 1313.938, 'start': 1161.262, 'weight': 0.814}, {'end': 1521.099, 'start': 1340.174, 'weight': 0.751}], 'summary': 'Tutorial covers implementing a queue using stacks, discussing enqueue and dequeue operations, two approaches to implement a queue using stacks with their time complexities, and the implementation of a queue using two stacks, along with c and dq operations in c programming, stack operations, and implementing stack and queue operations in c++.', 'chapters': [{'end': 439.654, 'segs': [{'end': 27.846, 'src': 'embed', 'start': 0.269, 'weight': 0, 'content': [{'end': 4.752, 'text': 'in this lecture we are going to see how to implement a queue using stacks.', 'start': 0.269, 'duration': 4.483}, {'end': 10.935, 'text': 'see, first of all, we will discuss the process of implementing a queue using stacks with the help of an example.', 'start': 4.752, 'duration': 6.183}, {'end': 13.077, 'text': 'then we will write down the code for this thing.', 'start': 10.935, 'duration': 2.142}, {'end': 21.001, 'text': 'fine, so now i hope everybody knows what is a queue and what is a stack, because we have already discussed about queues and stacks.', 'start': 13.077, 'duration': 7.924}, {'end': 25.424, 'text': 'you can find out the link of those videos in the i button as well as in the description box.', 'start': 21.001, 'duration': 4.423}, {'end': 27.846, 'text': 'fine, So Q follow which rules?', 'start': 25.424, 'duration': 2.422}], 'summary': 'Lecture on implementing queue using stacks, covers example and code, assumes prior knowledge of queues and stacks.', 'duration': 27.577, 'max_score': 0.269, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw269.jpg'}, {'end': 368.448, 'src': 'heatmap', 'start': 318.169, 'weight': 1, 'content': [{'end': 323.373, 'text': 'so here are two approaches, two methods to implement a queue using stacks, using two stacks.', 'start': 318.169, 'duration': 5.204}, {'end': 329.238, 'text': 'basically, you can implement a queue using one stack only right, using the recursion calls.', 'start': 323.373, 'duration': 5.865}, {'end': 332.861, 'text': 'but here we are discussing how to implement a queue using two stacks.', 'start': 329.238, 'duration': 3.623}, {'end': 339.106, 'text': 'so now, first method is here nq operation would take order of one time complexity,', 'start': 332.861, 'duration': 6.245}, {'end': 344.247, 'text': 'but dq operation would be take taking order of one n time complexity.', 'start': 339.106, 'duration': 5.141}, {'end': 347.828, 'text': 'so it means dq operation would be costly in this case.', 'start': 344.247, 'duration': 3.581}, {'end': 353.169, 'text': 'second method is here nq would take order of n time complexity and dq is taking order of one.', 'start': 347.828, 'duration': 5.341}, {'end': 356.769, 'text': 'so here, in this case, nq operation is costly, right.', 'start': 353.169, 'duration': 3.6}, {'end': 362.351, 'text': 'so here can you tell me which approach i have discussed with the help of this example.', 'start': 356.769, 'duration': 5.582}, {'end': 368.448, 'text': "see, i'm going to tell you here, whenever we are performing NQ operation, then simply what we did.", 'start': 362.351, 'duration': 6.097}], 'summary': 'Two methods to implement queue using stacks, with different time complexities for enqueue and dequeue operations.', 'duration': 44.182, 'max_score': 318.169, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw318169.jpg'}], 'start': 0.269, 'title': 'Implementing queue using stacks', 'summary': 'Explains the process of implementing a queue using stacks, demonstrating enqueue and dequeue operations, and discussing two approaches to implement a queue using stacks with their respective time complexities.', 'chapters': [{'end': 439.654, 'start': 0.269, 'title': 'Implementing queue using stacks', 'summary': 'Explains the process of implementing a queue using stacks, demonstrating the enqueue and dequeue operations, and discussing the two approaches to implement a queue using stacks with their respective time complexities.', 'duration': 439.385, 'highlights': ['The chapter explains the process of implementing a queue using stacks, demonstrating the enqueue and dequeue operations. It covers the concept of implementing a queue using stacks, including the demonstration of enqueue and dequeue operations.', 'Discussing the two approaches to implement a queue using stacks with their respective time complexities. The chapter discusses two approaches to implement a queue using stacks, highlighting the time complexities of enqueue and dequeue operations in each approach.', 'Enqueue operation takes order of one time complexity, but dequeue operation takes order of n time complexity in the first method. In the first method, enqueue operation has a time complexity of one, while dequeue operation has a time complexity of n.', 'In the second method, enqueue operation takes order of n time complexity, and dequeue operation takes order of one time complexity. The second method involves enqueue operation with a time complexity of n, while the dequeue operation has a time complexity of one.']}], 'duration': 439.385, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw269.jpg', 'highlights': ['The chapter explains the process of implementing a queue using stacks, demonstrating the enqueue and dequeue operations.', 'Discussing the two approaches to implement a queue using stacks with their respective time complexities.', 'In the second method, enqueue operation takes order of n time complexity, and dequeue operation takes order of one time complexity.', 'Enqueue operation takes order of one time complexity, but dequeue operation takes order of n time complexity in the first method.']}, {'end': 687.611, 'segs': [{'end': 531.468, 'src': 'embed', 'start': 459.83, 'weight': 0, 'content': [{'end': 462.711, 'text': 'i want to insert, i want to enqueue in this queue.', 'start': 459.83, 'duration': 2.881}, {'end': 465.051, 'text': 'the first of all five, then two, then minus one.', 'start': 462.711, 'duration': 2.34}, {'end': 470.573, 'text': 'then i want to dq one element, then again enqueue one element and then display.', 'start': 465.051, 'duration': 5.522}, {'end': 477.315, 'text': 'fine. so now see, we are going to take, we are going to use two stacks for this and we are going to implement this queue.', 'start': 470.573, 'duration': 6.742}, {'end': 481.297, 'text': 'this is just to make you understand how exactly Q is working.', 'start': 477.315, 'duration': 3.982}, {'end': 482.998, 'text': "we don't have this Q.", 'start': 481.297, 'duration': 1.701}, {'end': 486.781, 'text': 'actually we have only two stacks with us in the program.', 'start': 482.998, 'duration': 3.783}, {'end': 496.047, 'text': 'only see, I have taken two stacks, S1 and S2 right and I have taken that macro definition n is equal to five.', 'start': 486.781, 'duration': 9.266}, {'end': 498.568, 'text': "wherever in the program i'll use this n variable.", 'start': 496.047, 'duration': 2.521}, {'end': 500.409, 'text': 'then that would be replaced with this five.', 'start': 498.568, 'duration': 1.841}, {'end': 504.43, 'text': 'so it means you can say both s1 and s2 is having capacity of five.', 'start': 500.409, 'duration': 4.021}, {'end': 506.39, 'text': 'we can store only five elements, right.', 'start': 504.43, 'duration': 1.96}, {'end': 512.392, 'text': 'so you can say in a queue we can store only five elements because we are implementing a queue right.', 'start': 506.39, 'duration': 6.002}, {'end': 516.453, 'text': 'so we will actually push and pop data from here.', 'start': 512.392, 'duration': 4.061}, {'end': 522.235, 'text': "but i'm going to show you how actually the nq and dq operation is going to perform in q also fine.", 'start': 516.453, 'duration': 5.782}, {'end': 526.507, 'text': 'so now see, obviously we are taking top one.', 'start': 523.106, 'duration': 3.401}, {'end': 528.087, 'text': 'two elements would be there.', 'start': 526.507, 'duration': 1.58}, {'end': 531.468, 'text': 'this first stack one, top one is there and for this top two is there.', 'start': 528.087, 'duration': 3.381}], 'summary': 'Implementing queue using two stacks, with a capacity of five elements.', 'duration': 71.638, 'max_score': 459.83, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw459830.jpg'}, {'end': 666.385, 'src': 'embed', 'start': 638.188, 'weight': 6, 'content': [{'end': 642.139, 'text': 'suppose i am taking int count is equal to its starting.', 'start': 638.188, 'duration': 3.951}, {'end': 644.661, 'text': 'i am initializing it with zero.', 'start': 642.139, 'duration': 2.522}, {'end': 646.542, 'text': 'now, see, here also we have one problem.', 'start': 644.661, 'duration': 1.881}, {'end': 648.023, 'text': 'see push.', 'start': 646.542, 'duration': 1.481}, {'end': 651.846, 'text': 'we are going to perform push on stack one, also on stack two also.', 'start': 648.023, 'duration': 3.823}, {'end': 654.427, 'text': 'so you have to differentiate that function.', 'start': 651.846, 'duration': 2.581}, {'end': 657.429, 'text': 'so here i am performing this push operation on stack one.', 'start': 654.427, 'duration': 3.002}, {'end': 660.472, 'text': 'that is why i am taking push one here, not push.', 'start': 657.429, 'duration': 3.043}, {'end': 663.384, 'text': 'Here I am taking push1 operation.', 'start': 661.343, 'duration': 2.041}, {'end': 666.385, 'text': 'Similarly, we will take pop1 and pop2 right.', 'start': 663.384, 'duration': 3.001}], 'summary': 'Initializing count to zero. differentiating push operations for two stacks.', 'duration': 28.197, 'max_score': 638.188, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw638188.jpg'}], 'start': 439.654, 'title': 'Implementing queue with two stacks', 'summary': 'Discusses the implementation of a queue using two stacks, covering enqueue and dequeue operations with specific elements, and the logic behind push and pop operations, for better understanding.', 'chapters': [{'end': 482.998, 'start': 439.654, 'title': 'Implementing a queue with two stacks', 'summary': 'Discusses the implementation of a queue using two stacks, demonstrating the enqueue and dequeue operations with specific elements and explaining the concept for better understanding.', 'duration': 43.344, 'highlights': ['The video discusses the implementation of a queue using two stacks, exemplifying the enqueue operation three times, followed by dequeue, enqueue, and display operations.', 'The concept of using two stacks to implement a queue is explained to aid in understanding the working of a queue, emphasizing the absence of a specific queue structure.']}, {'end': 687.611, 'start': 482.998, 'title': 'Implementing queue with two stacks', 'summary': 'Explains the implementation of a queue using two stacks with a capacity of five elements each, covering the nq and dq operations, and the logic behind push and pop operations for the stacks.', 'duration': 204.613, 'highlights': ['The stacks S1 and S2 have a capacity of five elements each, allowing for the storage of only five elements in the queue implementation. The program uses two stacks, S1 and S2, each with a capacity of five elements, restricting the queue to store only five elements.', 'The nq and dq operations are performed on stack two, with the logic of pushing and popping elements being demonstrated through the use of a count variable. The nq and dq operations are executed on stack two, showcasing the logic of pushing and popping elements, along with the utilization of a count variable to manage the process.', 'The differentiation between push operations on stack one and stack two is achieved through the use of push1 and push2 functions, ensuring the correct execution of the respective push operations. The differentiation between push operations on stack one and stack two is facilitated by the use of push1 and push2 functions, ensuring the accurate execution of the push operations for the respective stacks.']}], 'duration': 247.957, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw439654.jpg', 'highlights': ['The video discusses the implementation of a queue using two stacks, exemplifying the enqueue operation three times, followed by dequeue, enqueue, and display operations.', 'The concept of using two stacks to implement a queue is explained to aid in understanding the working of a queue, emphasizing the absence of a specific queue structure.', 'The stacks S1 and S2 have a capacity of five elements each, allowing for the storage of only five elements in the queue implementation.', 'The program uses two stacks, S1 and S2, each with a capacity of five elements, restricting the queue to store only five elements.', 'The nq and dq operations are performed on stack two, with the logic of pushing and popping elements being demonstrated through the use of a count variable.', 'The nq and dq operations are executed on stack two, showcasing the logic of pushing and popping elements, along with the utilization of a count variable to manage the process.', 'The differentiation between push operations on stack one and stack two is achieved through the use of push1 and push2 functions, ensuring the correct execution of the respective push operations.', 'The differentiation between push operations on stack one and stack two is facilitated by the use of push1 and push2 functions, ensuring the accurate execution of the push operations for the respective stacks.']}, {'end': 912.384, 'segs': [{'end': 720.055, 'src': 'embed', 'start': 687.611, 'weight': 0, 'content': [{'end': 690.066, 'text': 'right, that thing i guess everybody know.', 'start': 687.611, 'duration': 2.455}, {'end': 695.848, 'text': "if you don't know, then we will discuss this thing also when we are going to start the c programming right.", 'start': 690.066, 'duration': 5.782}, {'end': 698.569, 'text': "i'm defining this push one here.", 'start': 695.848, 'duration': 2.721}, {'end': 699.229, 'text': 'see now.', 'start': 698.569, 'duration': 0.66}, {'end': 701.849, 'text': 'here this x value would be passed.', 'start': 699.229, 'duration': 2.62}, {'end': 706.211, 'text': 'so obviously, in definition also you need something to receive this value.', 'start': 701.849, 'duration': 4.362}, {'end': 710.512, 'text': 'so you need a variable here, int data or x, same variable name.', 'start': 706.211, 'duration': 4.301}, {'end': 710.992, 'text': 'you can take.', 'start': 710.512, 'duration': 0.48}, {'end': 714.273, 'text': "it's up to you, right, or a b, c as you wish.", 'start': 710.992, 'duration': 3.281}, {'end': 720.055, 'text': 'now, in push we are going to check the overflow condition also, if you want, right.', 'start': 714.273, 'duration': 5.782}], 'summary': 'Introduction to defining push function in c programming and handling overflow condition.', 'duration': 32.444, 'max_score': 687.611, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw687611.jpg'}, {'end': 764.567, 'src': 'embed', 'start': 733.101, 'weight': 1, 'content': [{'end': 741.025, 'text': 'so here you can write if top 1, because push 1 means we are talking about this stack.', 'start': 733.101, 'duration': 7.924}, {'end': 745.08, 'text': 'so top 1 is equal to, is equal to n minus 1.', 'start': 741.025, 'duration': 4.055}, {'end': 748.481, 'text': 'here you can simply write overflow condition right.', 'start': 745.08, 'duration': 3.401}, {'end': 754.383, 'text': 'else else we are going to push here.', 'start': 748.481, 'duration': 5.902}, {'end': 757.664, 'text': 'first thing is top one plus plus.', 'start': 754.383, 'duration': 3.281}, {'end': 759.485, 'text': 'we are going to increment this top now.', 'start': 757.664, 'duration': 1.821}, {'end': 762.106, 'text': 'top is zero, means top is pointing to here.', 'start': 759.485, 'duration': 2.621}, {'end': 764.567, 'text': 'now you can push here the data.', 'start': 762.106, 'duration': 2.461}], 'summary': 'Explaining how to handle stack overflow and pushing data in a stack.', 'duration': 31.466, 'max_score': 733.101, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw733101.jpg'}, {'end': 862.849, 'src': 'embed', 'start': 814.886, 'weight': 3, 'content': [{'end': 817.267, 'text': 'the control will go to the definition of the function.', 'start': 814.886, 'duration': 2.381}, {'end': 824.731, 'text': 'right. suppose i am writing this definition of push one operation before this nq operation, right.', 'start': 817.267, 'duration': 7.464}, {'end': 828.473, 'text': 'otherwise, if you will write here after this one, then it will give you an error.', 'start': 824.731, 'duration': 3.742}, {'end': 831.455, 'text': 'you have to declare this push one before this calling.', 'start': 828.473, 'duration': 2.982}, {'end': 835.677, 'text': 'right now the see, the condition is top one is equal to n minus one.', 'start': 831.455, 'duration': 4.222}, {'end': 837.498, 'text': 'this condition is not true else.', 'start': 835.677, 'duration': 1.821}, {'end': 838.698, 'text': 'so control will go into else.', 'start': 837.498, 'duration': 1.2}, {'end': 842.621, 'text': 'part top one plus plus means top is now zero s one.', 'start': 838.698, 'duration': 3.923}, {'end': 844.041, 'text': 'zero is equal to data.', 'start': 842.621, 'duration': 1.42}, {'end': 845.462, 'text': 'so data is what five.', 'start': 844.041, 'duration': 1.421}, {'end': 846.723, 'text': 'so five would be inserted here.', 'start': 845.462, 'duration': 1.261}, {'end': 850.864, 'text': 'Again, call this enqueue here x value is 2.', 'start': 847.523, 'duration': 3.341}, {'end': 852.305, 'text': 'push 1 2 would be called.', 'start': 850.864, 'duration': 1.441}, {'end': 859.028, 'text': 'Now see one thing again after this calling the control will go back to here and count plus plus.', 'start': 852.725, 'duration': 6.303}, {'end': 862.849, 'text': 'Now count becomes 1 that you need to take care.', 'start': 859.528, 'duration': 3.321}], 'summary': 'The function definition and operations are discussed, including inserting data and managing counts.', 'duration': 47.963, 'max_score': 814.886, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw814886.jpg'}], 'start': 687.611, 'title': 'C and dq operations in c programming', 'summary': 'Covers the implementation of a stack in c programming, discussing push operation, overflow condition check, and variable naming conventions, along with explaining the dq operation and function calls, detailing the process of function calls and data insertion with specific examples and conditions.', 'chapters': [{'end': 789.691, 'start': 687.611, 'title': 'C programming: stack implementation', 'summary': 'Covers the implementation of a stack in c programming, discussing the push operation, overflow condition check, and variable naming conventions.', 'duration': 102.08, 'highlights': ["The push operation in C programming is defined, with a discussion on the variable naming conventions, such as using 'data' instead of 'x' as it is a local variable.", 'The chapter explains the implementation of the overflow condition check in the push operation to determine if the stack is full, with a specific example of checking if the top is equal to n minus 1.', 'The increment of the top pointer and the insertion of data into the stack are elucidated as part of the push operation in C programming.']}, {'end': 912.384, 'start': 789.691, 'title': 'Dq operation and function calls', 'summary': 'Explains the dq operation and function calls, detailing the process of function calls and data insertion with specific examples and conditions.', 'duration': 122.693, 'highlights': ['Control flow and sequence of function calls, detailing the insertion of data and increment of count and top variables.', 'Explanation of conditions for data insertion and increment of count and top variables during function calls.', "Importance of sequence and declaration of 'push one' operation in relation to 'nq' operation."]}], 'duration': 224.773, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw687611.jpg', 'highlights': ["The push operation in C programming is defined, with a discussion on the variable naming conventions, such as using 'data' instead of 'x' as it is a local variable.", 'The chapter explains the implementation of the overflow condition check in the push operation to determine if the stack is full, with a specific example of checking if the top is equal to n minus 1.', 'The increment of the top pointer and the insertion of data into the stack are elucidated as part of the push operation in C programming.', 'Control flow and sequence of function calls, detailing the insertion of data and increment of count and top variables.', 'Explanation of conditions for data insertion and increment of count and top variables during function calls.', "Importance of sequence and declaration of 'push one' operation in relation to 'nq' operation."]}, {'end': 1161.262, 'segs': [{'end': 944.121, 'src': 'embed', 'start': 912.384, 'weight': 0, 'content': [{'end': 913.304, 'text': 'now count becomes 3.', 'start': 912.384, 'duration': 0.92}, {'end': 917.547, 'text': 'right now, see what.', 'start': 913.304, 'duration': 4.243}, {'end': 922.368, 'text': 'the next is what dq now how you will dequeue, see.', 'start': 917.547, 'duration': 4.821}, {'end': 928.632, 'text': 'i have told you, the processor, first of all, pop all the elements until the stack one becomes empty.', 'start': 922.368, 'duration': 6.264}, {'end': 931.634, 'text': 'push these elements in stack two.', 'start': 928.632, 'duration': 3.002}, {'end': 934.495, 'text': 'after that pop from stack two.', 'start': 931.634, 'duration': 2.861}, {'end': 936.497, 'text': 'see this process for dequeuing.', 'start': 934.495, 'duration': 2.002}, {'end': 939.698, 'text': 'first of all, pop all the element from s1, push here.', 'start': 936.497, 'duration': 3.201}, {'end': 940.619, 'text': 'then pop from s2.', 'start': 939.698, 'duration': 0.921}, {'end': 944.121, 'text': 'then again remaining element would be pushed back to s1.', 'start': 940.619, 'duration': 3.502}], 'summary': 'Dequeue process: pop all from s1, push to s2, then pop from s2.', 'duration': 31.737, 'max_score': 912.384, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw912384.jpg'}, {'end': 996.553, 'src': 'embed', 'start': 967.07, 'weight': 2, 'content': [{'end': 972.337, 'text': 'first of all, you can check if there is nothing in stack one and stack two.', 'start': 967.07, 'duration': 5.267}, {'end': 976.223, 'text': 'then you cannot pop anything means q is empty.', 'start': 972.337, 'duration': 3.886}, {'end': 981.803, 'text': 'so here you can write if Top 1 equal to equal to minus 1..', 'start': 976.223, 'duration': 5.58}, {'end': 985.005, 'text': 'And top 2 equal to equal to minus 1.', 'start': 981.803, 'duration': 3.202}, {'end': 986.546, 'text': 'Then here you can print simply.', 'start': 985.005, 'duration': 1.541}, {'end': 988.347, 'text': 'Q is empty.', 'start': 986.626, 'duration': 1.721}, {'end': 990.569, 'text': 'Else In else part.', 'start': 988.628, 'duration': 1.941}, {'end': 991.529, 'text': 'What you will write.', 'start': 990.789, 'duration': 0.74}, {'end': 994.291, 'text': 'Obviously we are going to pop these elements.', 'start': 992.13, 'duration': 2.161}, {'end': 996.553, 'text': 'So we need a for loop.', 'start': 994.611, 'duration': 1.942}], 'summary': "Check if stack 1 and stack 2 are empty, print 'q is empty', else pop elements using a for loop.", 'duration': 29.483, 'max_score': 967.07, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw967070.jpg'}, {'end': 1161.262, 'src': 'embed', 'start': 1110.935, 'weight': 1, 'content': [{'end': 1115.738, 'text': 'i value is less than count and count is three and i value zero.', 'start': 1110.935, 'duration': 4.803}, {'end': 1116.939, 'text': 'then i value becomes one.', 'start': 1115.738, 'duration': 1.201}, {'end': 1119.12, 'text': 'then i value becomes two means three times.', 'start': 1116.939, 'duration': 2.181}, {'end': 1120.722, 'text': 'this loop would be executed.', 'start': 1119.12, 'duration': 1.602}, {'end': 1127.328, 'text': 'so three times means one, two and three, all the values we can popped and pushed in stack two.', 'start': 1120.722, 'duration': 6.606}, {'end': 1134.914, 'text': 'so after that this two, after that this five, after popping all the values, this top one value becomes minus one.', 'start': 1127.328, 'duration': 7.586}, {'end': 1139.298, 'text': 'again, right, and here the top two becomes.', 'start': 1134.914, 'duration': 4.384}, {'end': 1143.702, 'text': 'value becomes now two means top two is pointing to here now.', 'start': 1139.298, 'duration': 4.404}, {'end': 1148.466, 'text': 'next thing is you can, now you will pop out from stack two.', 'start': 1143.702, 'duration': 4.764}, {'end': 1157.079, 'text': 'so now here you will write what pop 2, because we are calling pop operation on stack 2.', 'start': 1148.466, 'duration': 8.613}, {'end': 1161.262, 'text': 'so pop 2, whatever suppose the value, this return, pop 2, return.', 'start': 1157.079, 'duration': 4.183}], 'summary': 'Loop executed 3 times, values pushed in stack 2, top 2 becomes 2, pop 2 returns value', 'duration': 50.327, 'max_score': 1110.935, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw1110935.jpg'}], 'start': 912.384, 'title': 'Stack operations', 'summary': 'Covers dequeuing elements from a stack, involving popping and pushing elements between two stacks, and executing value shuffling using pop and push operations, manipulation of stack pointers, and iteration of a loop.', 'chapters': [{'end': 1027.531, 'start': 912.384, 'title': 'Dequeuing process in a stack', 'summary': 'Discusses the process of dequeuing elements from a stack, involving the steps of popping and pushing elements between two stacks and implementing a loop to check for empty queue conditions.', 'duration': 115.147, 'highlights': ['The process of dequeuing involves popping all elements from stack one, pushing them to stack two, and then popping from stack two.', 'To check for an empty queue, a for loop is used to iterate through the elements in the stack and execute the necessary popping and pushing operations.']}, {'end': 1161.262, 'start': 1027.531, 'title': 'Stack operations and value shuffling', 'summary': 'Explains the process of popping and pushing values between two stacks, with key points including the use of pop and push operations, the manipulation of stack pointers, and the iteration of a loop to execute the shuffling of values between the stacks.', 'duration': 133.731, 'highlights': ['The while loop executes three times, allowing for the popping and pushing of all values between the two stacks, totaling in three iterations.', 'The top value of stack one becomes minus one after popping all the values, while the top value of stack two becomes two after pushing the values from stack one.', 'The process involves calling pop and push operations on two stacks, manipulating the stack pointers, and shuffling values between the stacks.']}], 'duration': 248.878, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw912384.jpg', 'highlights': ['The process of dequeuing involves popping all elements from stack one, pushing them to stack two, and then popping from stack two.', 'The process involves calling pop and push operations on two stacks, manipulating the stack pointers, and shuffling values between the stacks.', 'To check for an empty queue, a for loop is used to iterate through the elements in the stack and execute the necessary popping and pushing operations.', 'The while loop executes three times, allowing for the popping and pushing of all values between the two stacks, totaling in three iterations.', 'The top value of stack one becomes minus one after popping all the values, while the top value of stack two becomes two after pushing the values from stack one.']}, {'end': 1489.394, 'segs': [{'end': 1313.938, 'src': 'heatmap', 'start': 1161.262, 'weight': 0.814, 'content': [{'end': 1172.533, 'text': 'we are going to store in a variable b, and if you want to print the popped or the dequeued element is so here simply you can write printf.', 'start': 1161.262, 'duration': 11.271}, {'end': 1177.416, 'text': "the dequeued element is I'm not writing the complete sentence, and here you can print this B right?", 'start': 1172.533, 'duration': 4.883}, {'end': 1179.837, 'text': 'So you are taking here B and A also.', 'start': 1177.856, 'duration': 1.981}, {'end': 1187.543, 'text': 'So here you are, you need to declare A and B also in this function definition, right? Now this is not yet done.', 'start': 1179.897, 'duration': 7.646}, {'end': 1191.165, 'text': 'What you need to do now again.', 'start': 1187.783, 'duration': 3.382}, {'end': 1195.808, 'text': 'see, after popping this, we have popped out this five right?', 'start': 1191.165, 'duration': 4.643}, {'end': 1197.609, 'text': 'And we have the output.', 'start': 1196.248, 'duration': 1.361}, {'end': 1199.831, 'text': 'is, we have printed this five right?', 'start': 1197.609, 'duration': 2.222}, {'end': 1204.206, 'text': 'and according to q, what should be the output?', 'start': 1202.324, 'duration': 1.882}, {'end': 1211.632, 'text': 'c, nq, 5, then 2, then minus 1, and if you perform dequeue, then from the front it would be dequeued.', 'start': 1204.206, 'duration': 7.426}, {'end': 1215.295, 'text': 'so output would be 5 and we are getting 5 only.', 'start': 1211.632, 'duration': 3.663}, {'end': 1221.56, 'text': 'it means we have successfully implemented both nq and dequeue operations on stacks and we have implemented a q.', 'start': 1215.295, 'duration': 6.265}, {'end': 1225.691, 'text': 'now what you need to do again?', 'start': 1222.87, 'duration': 2.821}, {'end': 1230.112, 'text': 'pop these elements from here and push in stack one again.', 'start': 1225.691, 'duration': 4.421}, {'end': 1231.713, 'text': 'so now this is not yet done.', 'start': 1230.112, 'duration': 1.601}, {'end': 1236.374, 'text': 'what you need to do after maybe you printing this dequeued element in the queue?', 'start': 1231.713, 'duration': 4.661}, {'end': 1242.576, 'text': 'now i have only two element, because i have enqueued three element, one element i have dequeued.', 'start': 1236.374, 'duration': 6.202}, {'end': 1245.637, 'text': 'so basically, count should be now 2.', 'start': 1242.576, 'duration': 3.061}, {'end': 1248.759, 'text': 'so you have to decrement this count now.', 'start': 1245.637, 'duration': 3.122}, {'end': 1258.264, 'text': "so after this line, whatever you will write, i'm writing here because i don't have so much space now count minus, minus right.", 'start': 1248.759, 'duration': 9.505}, {'end': 1261.463, 'text': 'so now count becomes 2 Right.', 'start': 1258.264, 'duration': 3.199}, {'end': 1263.845, 'text': 'Because actually we are having only 2 elements.', 'start': 1261.723, 'duration': 2.122}, {'end': 1269.929, 'text': 'Now we are going to again push back these elements into stack 1.', 'start': 1264.646, 'duration': 5.283}, {'end': 1272.331, 'text': 'Right So again you will write down a for loop.', 'start': 1269.929, 'duration': 2.402}, {'end': 1274.253, 'text': 'For i is equal to 0.', 'start': 1272.731, 'duration': 1.522}, {'end': 1275.333, 'text': 'i less than count.', 'start': 1274.253, 'duration': 1.08}, {'end': 1276.214, 'text': 'Same for loop.', 'start': 1275.453, 'duration': 0.761}, {'end': 1277.855, 'text': 'i plus plus.', 'start': 1277.035, 'duration': 0.82}, {'end': 1284.26, 'text': 'And now here the situation is we are popping from stack 2.', 'start': 1279.556, 'duration': 4.704}, {'end': 1286.582, 'text': 'So first of all we will call pop.', 'start': 1284.26, 'duration': 2.322}, {'end': 1290.58, 'text': '2. here we are calling pop 1.', 'start': 1288.098, 'duration': 2.482}, {'end': 1292.502, 'text': 'whatever this will return.', 'start': 1290.58, 'duration': 1.922}, {'end': 1295.984, 'text': 'suppose I am storing in A.', 'start': 1292.502, 'duration': 3.482}, {'end': 1298.606, 'text': 'now in A I have 2.', 'start': 1295.984, 'duration': 2.622}, {'end': 1305.471, 'text': 'right now this top 2 is having 1 after deleting this right after popping this.', 'start': 1298.606, 'duration': 6.865}, {'end': 1313.938, 'text': 'so now I will call push 1 because I am pushing in S1 right and here I will pass A.', 'start': 1305.471, 'duration': 8.467}], 'summary': 'Implemented nq and dequeue operations on stacks, successfully dequeued 5 elements, count is now 2.', 'duration': 152.676, 'max_score': 1161.262, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw1161262.jpg'}, {'end': 1236.374, 'src': 'embed', 'start': 1187.783, 'weight': 0, 'content': [{'end': 1191.165, 'text': 'What you need to do now again.', 'start': 1187.783, 'duration': 3.382}, {'end': 1195.808, 'text': 'see, after popping this, we have popped out this five right?', 'start': 1191.165, 'duration': 4.643}, {'end': 1197.609, 'text': 'And we have the output.', 'start': 1196.248, 'duration': 1.361}, {'end': 1199.831, 'text': 'is, we have printed this five right?', 'start': 1197.609, 'duration': 2.222}, {'end': 1204.206, 'text': 'and according to q, what should be the output?', 'start': 1202.324, 'duration': 1.882}, {'end': 1211.632, 'text': 'c, nq, 5, then 2, then minus 1, and if you perform dequeue, then from the front it would be dequeued.', 'start': 1204.206, 'duration': 7.426}, {'end': 1215.295, 'text': 'so output would be 5 and we are getting 5 only.', 'start': 1211.632, 'duration': 3.663}, {'end': 1221.56, 'text': 'it means we have successfully implemented both nq and dequeue operations on stacks and we have implemented a q.', 'start': 1215.295, 'duration': 6.265}, {'end': 1225.691, 'text': 'now what you need to do again?', 'start': 1222.87, 'duration': 2.821}, {'end': 1230.112, 'text': 'pop these elements from here and push in stack one again.', 'start': 1225.691, 'duration': 4.421}, {'end': 1231.713, 'text': 'so now this is not yet done.', 'start': 1230.112, 'duration': 1.601}, {'end': 1236.374, 'text': 'what you need to do after maybe you printing this dequeued element in the queue?', 'start': 1231.713, 'duration': 4.661}], 'summary': 'Successfully implemented nq and dequeue operations on stacks and implemented a q.', 'duration': 48.591, 'max_score': 1187.783, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw1187783.jpg'}, {'end': 1469.138, 'src': 'embed', 'start': 1436.466, 'weight': 3, 'content': [{'end': 1445.271, 'text': 'here stack name is stack 2, because we are performing pop 2 in stack 2 and here top 2, whatever the value in top 2,', 'start': 1436.466, 'duration': 8.805}, {'end': 1448.053, 'text': 'that would be returned and after that we will do top, minus, minus.', 'start': 1445.271, 'duration': 2.782}, {'end': 1451.935, 'text': 'so that is post decrement.', 'start': 1448.053, 'duration': 3.882}, {'end': 1454.857, 'text': 'now what about this push 2?', 'start': 1451.935, 'duration': 2.922}, {'end': 1457.418, 'text': 'this is same as push 1.', 'start': 1454.857, 'duration': 2.561}, {'end': 1460.16, 'text': 'the only difference is what.', 'start': 1457.418, 'duration': 2.742}, {'end': 1465.548, 'text': 'here you will write push 2 in top.', 'start': 1460.16, 'duration': 5.388}, {'end': 1469.138, 'text': 'we are checking condition on top 2 right now.', 'start': 1465.548, 'duration': 3.59}], 'summary': 'Stack 2 performs pop 2 and post-decrement, also includes push 2 with condition on top 2.', 'duration': 32.672, 'max_score': 1436.466, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw1436466.jpg'}], 'start': 1161.262, 'title': 'Implementing stack and queue operations', 'summary': 'Discusses implementing enqueue and dequeue operations on stacks and queues, and successfully implementing a queue with the output of 5 after performing dequeue. it also explains the implementation of stack operations in c++ including enqueue, dequeue, push, and pop with a detailed explanation of the code and its functionality.', 'chapters': [{'end': 1236.374, 'start': 1161.262, 'title': 'Implementing stack and queue operations', 'summary': 'Discusses implementing both enqueue and dequeue operations on stacks and queues, and successfully implementing a queue with the output of 5 after performing dequeue.', 'duration': 75.112, 'highlights': ['Successfully implemented both nq and dequeue operations on stacks and queues, and have implemented a q.', 'The output of 5 after performing dequeue operation.']}, {'end': 1489.394, 'start': 1236.374, 'title': 'Stack operations in c++', 'summary': 'Explains the implementation of stack operations in c++ including enqueue, dequeue, push, and pop with a detailed explanation of the code and its functionality.', 'duration': 253.02, 'highlights': ['The code explains the implementation of stack operations in C++ including enqueue, dequeue, push, and pop with detailed code explanation.', 'The detailed explanation includes the implementation of push and pop operations, as well as the handling of stack count and top values.', 'The code provides a step-by-step explanation of the implementation of enqueue and dequeue operations, including the definition of push and pop functions for stack manipulation.']}], 'duration': 328.132, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw1161262.jpg', 'highlights': ['Successfully implemented both nq and dequeue operations on stacks and queues, and have implemented a q.', 'The output of 5 after performing dequeue operation.', 'The code explains the implementation of stack operations in C++ including enqueue, dequeue, push, and pop with detailed code explanation.', 'The detailed explanation includes the implementation of push and pop operations, as well as the handling of stack count and top values.', 'The code provides a step-by-step explanation of the implementation of enqueue and dequeue operations, including the definition of push and pop functions for stack manipulation.']}, {'end': 1745.227, 'segs': [{'end': 1541.95, 'src': 'embed', 'start': 1511.733, 'weight': 0, 'content': [{'end': 1514.356, 'text': 'actually, this is just for you guys to make understand.', 'start': 1511.733, 'duration': 2.623}, {'end': 1521.099, 'text': 'fine, we have these two stacks, so the output should be 2, minus 1 right now.', 'start': 1514.356, 'duration': 6.743}, {'end': 1525.801, 'text': 'see, we cannot print from here minus one and two because according to the queue we are implementing queue.', 'start': 1521.099, 'duration': 4.702}, {'end': 1527.602, 'text': 'so the output should be two, minus one.', 'start': 1525.801, 'duration': 1.801}, {'end': 1531.884, 'text': 'so now we are going to display whatever the content in stack one.', 'start': 1527.602, 'duration': 4.282}, {'end': 1532.725, 'text': 'why stack one?', 'start': 1531.884, 'duration': 0.841}, {'end': 1536.687, 'text': 'because stack two is only a temporary type of stack.', 'start': 1532.725, 'duration': 3.962}, {'end': 1541.95, 'text': "or you can say it's a supportive step when you are performing the dq operation.", 'start': 1536.687, 'duration': 5.263}], 'summary': 'Explanation of implementing a queue using two stacks, with an output of 2 and minus 1, focusing on the temporary role of stack two.', 'duration': 30.217, 'max_score': 1511.733, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw1511733.jpg'}, {'end': 1742.363, 'src': 'embed', 'start': 1716.117, 'weight': 2, 'content': [{'end': 1720.16, 'text': 'you can implement using two stacks also implement, but you will not follow this approach.', 'start': 1716.117, 'duration': 4.043}, {'end': 1723.763, 'text': 'you will not take this count variable and you can apply your own logic.', 'start': 1720.16, 'duration': 3.603}, {'end': 1732.05, 'text': 'so this is only just one way out of all the possible ways you can develop your own logic and you can implement this queue using stacks right.', 'start': 1723.763, 'duration': 8.287}, {'end': 1736.276, 'text': 'So now, in next video, we are going to see how to implement a stack using queues.', 'start': 1732.791, 'duration': 3.485}, {'end': 1739.8, 'text': 'As well as we will see, I am going to start about trees.', 'start': 1736.476, 'duration': 3.324}, {'end': 1742.363, 'text': 'We will see the introductory part of trees.', 'start': 1739.98, 'duration': 2.383}], 'summary': 'Implement a queue using stacks, and upcoming topics: stack using queues and introduction to trees.', 'duration': 26.246, 'max_score': 1716.117, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw1716117.jpg'}], 'start': 1489.394, 'title': 'Implementing queue using stacks', 'summary': "Explains the process of implementing a queue using stacks, with an emphasis on code examples and potential issues, encouraging the development of one's own logic. it ensures the output is 2, minus 1.", 'chapters': [{'end': 1585.139, 'start': 1489.394, 'title': 'Queue display function', 'summary': 'Explains the process of displaying the content of a queue using two stacks, ensuring the output is 2, minus 1.', 'duration': 95.745, 'highlights': ['The output of the display function for the queue should be 2, minus 1, as stack two is a temporary supportive stack used during the dequeue operation, and the data is maintained in stack one.', 'The process involves using a for loop to display the elements in stack one, which results in the output being 2, minus 1.']}, {'end': 1745.227, 'start': 1585.139, 'title': 'Implementing queue using stacks', 'summary': "Explains how to implement a queue using stacks, demonstrating the process with code examples and discussing the potential issues with using a count variable in the implementation, emphasizing the possibility of multiple approaches and encouraging the development of one's own logic.", 'duration': 160.088, 'highlights': ['The chapter explains how to implement a queue using stacks Demonstrates the process with code examples and discusses the potential issues with using a count variable in the implementation', "Emphasizes the possibility of multiple approaches and encourages the development of one's own logic Stresses the potential for various ways to implement a queue using stacks and encourages the viewer to develop their own logic", 'Discusses the process with code examples and potential issues with using a count variable in the implementation Provides insights into the process of implementing a queue using stacks and highlights potential issues with using a count variable']}], 'duration': 255.833, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/EFO7bbFcOMw/pics/EFO7bbFcOMw1489394.jpg', 'highlights': ['The output of the display function for the queue should be 2, minus 1, as stack two is a temporary supportive stack used during the dequeue operation, and the data is maintained in stack one.', 'The process involves using a for loop to display the elements in stack one, which results in the output being 2, minus 1.', 'The chapter explains how to implement a queue using stacks Demonstrates the process with code examples and discusses the potential issues with using a count variable in the implementation', "Emphasizes the possibility of multiple approaches and encourages the development of one's own logic Stresses the potential for various ways to implement a queue using stacks and encourages the viewer to develop their own logic", 'Discusses the process with code examples and potential issues with using a count variable in the implementation Provides insights into the process of implementing a queue using stacks and highlights potential issues with using a count variable']}], 'highlights': ['The chapter explains the process of implementing a queue using stacks, demonstrating the enqueue and dequeue operations.', 'The video discusses the implementation of a queue using two stacks, exemplifying the enqueue operation three times, followed by dequeue, enqueue, and display operations.', 'The process of dequeuing involves popping all elements from stack one, pushing them to stack two, and then popping from stack two.', 'The code explains the implementation of stack operations in C++ including enqueue, dequeue, push, and pop with detailed code explanation.', 'The output of the display function for the queue should be 2, minus 1, as stack two is a temporary supportive stack used during the dequeue operation, and the data is maintained in stack one.']}