![]() ![]() The "real-life" examples are pretty clearly delineated here already, but since you asked for examples in programming as well, I'll add one to the list. When a link is pressed, a new element is pushed onto the stack. When pressing the "back" button, the stack's pop function is called, and you get redirected to that. The browser has a stack with the links (technically, sort of cached versions) of pages you've been to. (more on this can be seen here)Īnother handy example is the browser back button. The very obvious usage of stack is, of course, the stack segment of computer memory. I'll check that and edit this post when I have a definite answer about this particular part). Also, revisions of posts on Stack Exchange have some form of a Stack (funny coincidence, isn't it?) to save the revisions (though I think the SE system uses partial functionality of a stack. For example, many text editors use a stack data structure to save the changes made to the file. (Initializing the stack - creating a new stack)ġThe initializing of the stack isn't exactly a special operation a stack can do.Ī stack is something used in programming when you need to keep a record of the history of versions.Check if Empty - check if the stack is empty (in the analogy, this operation is checking if there are bullets left).Peek - looking at the first element of the stack (checking to make sure that the topmost bullet is correctly placed).Pop - remove the top element (bullet) from the stack (in the analogy, this is like shooting). ![]() Push - adding a new element (bullet) to the top.A magazine works by LIFO (Last In First Out), and so does a Stack.įurthermore, the four (five 1) basic operations of a Stack are applicable: It is easy to see that bullets can be inserted from the top, and only the topmost bullet is accessible. A rather interesting analogy is that of a firearms magazine. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |