Hitting Undo again after this will have no effect because your undo stack is empty, at least in most editors. This removes the Delete Word item, leaving only one operation on the stack.įinally, if you hit Undo a third time, then the last item will be popped off the stack: When you hit undo again, the next item is popped off the stack: This operation is the opposite of push and is commonly called pop. Your editor undoes the indent, and the undo stack now contains two items. ![]() It takes the item at the top of the stack, which was indenting the comment, and removes that from the stack: Now you’ve decided to undo all three of those changes, so you hit the undo command. When you’re working with stacks, adding new items like this is called push. You can see that each of these commands are stored in an undo stack, with each new command being put at the top. Finally you indent a comment so that it’s lined up properly: Notice how the Delete Word item is placed on top of the stack. After adding the function, you delete a word from a comment. You can see that the stack now has an Add Function operation on it. Let’s imagine you’re editing a Python file so we can look at some of the operations you perform. ![]() ![]() It’s probably easiest to understand a stack if you think of a use case you’re likely familiar with: the Undo feature in your editor. This is in contrast to a queue, which stores items in a First-In/First-Out (FIFO) manner. What Is a Stack?Ī stack is a data structure that stores items in an Last-In/First-Out manner. Free Bonus: Click here to get a Python Cheat Sheet and learn the basics of Python 3, like working with data types, dictionaries, lists, and Python functions.
0 Comments
Leave a Reply. |