no functors for now

This commit is contained in:
Jidong Xiao
2025-02-24 21:14:19 -05:00
committed by JamesFlare
parent 0772468c29
commit bcbf1ac700

View File

@@ -1,30 +1,10 @@
# Lecture 14 --- Stack and Queue # Lecture 14 --- Stack and Queue
<!--## Test 2 Information
- Test 2 will be held Thursday, February 29th, 2024 from 6-7:50pm.
- No make-ups will be given except for pre-approved absence or illness, and a written excuse from the Dean of Students or the Student Experience office or the RPI Health Center will be required.
- If you have a letter from Disability Services for Students and you have not already emailed it to ds_instructors@cs.rpi.edu, please do so ASAP. Shianne Hulbert will be in contact with you about your accommodations for the test. And you will go to Lally 102 for the test.
- Students assigned test room, row, and seat assignments will be re-randomized. If you dont have a seating assignment when you log onto Submitty, let us know via the ds_instructors list.
- Coverage: Lectures 1-14, Labs 1-7, HW 1-5.
- OPTIONAL: you are allowed to bring two physical pieces of 8.5x11” paper, thats four “sides”. We will check at the start of the exam that you do not have more than two pieces of paper for your notes!
- All students must bring their Rensselaer photo ID card.
- Bring pencil(s) & eraser (pens are ok, but not recommended).
- Computers, cell-phones, smart watches, calculators, music players, etc. are not permitted.
- Practice problems from previous tests are available on the [course materials](https://submitty.cs.rpi.edu/courses/s24/csci1200/course_materials) page on Submitty.
## Other Announcements
- Resources will be dedicated to test grading and thus no office hours on Friday in test weeks. (week of test 1, week of test 2, week of test 3)
- Jidong's new office hours (effective after the spring break): Monday 2-4pm, Wednesday 1-3pm.
- HW6 will be ready on Thursday night 10pm. Only 10 students passed all test cases last semester. Not just because it's hard, it's just that submitty will stop your program if it runs too long. In order to pass some of the tricky test cases, your program must be fast enough.-->
## Todays Lecture ## Todays Lecture
- Function Objects
- STL Queue and STL Stack - STL Queue and STL Stack
## 14.0 Some Special Syntax <!-- ## 14.0 Some Special Syntax
The following program demonstrates some special syntax about C++ constructors. The following program demonstrates some special syntax about C++ constructors.
@@ -164,8 +144,9 @@ int main() {
``` ```
- You can compile and run this [example](multiply.cpp). - You can compile and run this [example](multiply.cpp).
-->
## 14.4 Additional STL Container Classes: Stacks ## 14.1 Additional STL Container Classes: Stacks
<!--Weve studied STL vectors, lists, maps, and sets. These data structures provide a wide range of flexibility in <!--Weve studied STL vectors, lists, maps, and sets. These data structures provide a wide range of flexibility in
terms of operations. One way to obtain computational efficiency is to consider a simplified set of operations or terms of operations. One way to obtain computational efficiency is to consider a simplified set of operations or
@@ -178,7 +159,7 @@ functionality.-->
- Stacks may be implemented efficiently in terms of vectors and lists, although vectors are preferable. - Stacks may be implemented efficiently in terms of vectors and lists, although vectors are preferable.
- All stack operations are O(1). - 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. - push(const T& value): Adds an element value to the top of the stack.
- pop(): Removes the top element from 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. - 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. - 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. - 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). 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. - 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. - 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. - 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). - 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. - 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. - 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. - 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. - 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. - 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). 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 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). - [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).