From bcbf1ac700446ac1f4b252c41051f40cf838e233 Mon Sep 17 00:00:00 2001 From: Jidong Xiao Date: Mon, 24 Feb 2025 21:14:19 -0500 Subject: [PATCH] no functors for now --- lectures/14_stacks_queues/README.md | 37 +++++++---------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/lectures/14_stacks_queues/README.md b/lectures/14_stacks_queues/README.md index 2bc0e00..6e1f877 100644 --- a/lectures/14_stacks_queues/README.md +++ b/lectures/14_stacks_queues/README.md @@ -1,30 +1,10 @@ # Lecture 14 --- Stack and Queue - - ## Today’s Lecture -- Function Objects - STL Queue and STL Stack -## 14.0 Some Special Syntax + -## 14.4 Additional STL Container Classes: Stacks +## 14.1 Additional STL Container Classes: Stacks - Stacks may be implemented efficiently in terms of vectors and lists, although vectors are preferable. - All stack operations are O(1). -### 14.4.1 Member functions of std::stack +### 14.1.1 Member functions of std::stack - push(const T& value): Adds an element value to the top of the stack. - pop(): Removes the top element from the stack. @@ -186,7 +167,7 @@ functionality.--> - empty(): Checks if the stack is empty. Returns true if the stack is empty, false otherwise. - size(): Returns the number of elements in the stack. -### 14.4.2 Stack Example Program +### 14.1.2 Stack Example Program - Following is an example program, remember to include the stack library. @@ -222,7 +203,7 @@ int main() { You can compile and run this above [program](stack.cpp). -## 14.5 Additional STL Container Classes: Queues +## 14.2 Additional STL Container Classes: Queues - A queue is a linear data structure that follows the First-In-First-Out (FIFO) principle. - Queues allow insertion at one end, called the back and removal from the other end, called the front. @@ -230,7 +211,7 @@ You can compile and run this above [program](stack.cpp). - Queues may be implemented efficiently in terms of a list. Using vectors for queues is also possible, but requires more work to get right. - All queue operations are O(1). -### 14.5.1 Member functions of std::queue +### 14.2.1 Member functions of std::queue - push(const T& value): Adds an element value to the rear of the queue. This operation is also known as enqueue. - pop(): Removes the front element from the queue. This operation is also known as dequeue. @@ -238,7 +219,7 @@ You can compile and run this above [program](stack.cpp). - empty(): Checks if the queue is empty. Returns true if the queue is empty, false otherwise. - size(): Returns the number of elements in the queue. -### 14.5.2 Queue Example Program +### 14.2.2 Queue Example Program - Following is an example program, remember to include the queue library. @@ -274,7 +255,7 @@ int main() { You can compile and run this above [program](queue.cpp). -## 14.6 Leetcode Exercises +## 14.3 Leetcode Exercises - [Leetcode problem 225: Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues/). Solution: [p225_stack_using_queues.cpp](../../leetcode/p225_stack_using_queues.cpp). - [Leetcode problem 232: Implement Queue using Stacks](https://leetcode.com/problems/implement-queue-using-stacks/). Solution: [p232_queue_using_stacks.cpp](../../leetcode/p232_queue_using_stacks.cpp).