

If you call the pop operation, you’ll get back item six, and that item will be removed from the stack, like the following image illustrates: Now you can push another item on the stack, or you can pop an item from the stack. Now you have six items on the stack, and item five is no longer available to you, like so: You can push an item onto your stack, let’ say you want to push item six on it: Let’s say you have five items on your stack like the image below shows: Pop will return the item, and delete it from the stack, and peek will allow you to see what the item at the top of the stack is, but it will not remove it. Push will, obviously, push an item onto a stack.

Some common operations on a stack are push, pop and peek. If you’re getting hundreds of mails a day, this might mean you’ll never see some of the mails that are on the bottom of your stack. The most recent mail will be shown at the top, and if you read your mails from top to bottom, you’ll read your most recent mails first. I good analogy would be your email inbox. Which basically means, the last element that you add to the stack is the first one that you’ll pull out.

Stack is a LIFO data structure ( Last In First Out). We’ll implement it using another data structure called a ‘Linked List’, and for the sake of comparison, we will implement the same stack data structure using plain old arrays, and compare performances between the two. In this post we will examine one such structure called a ‘Stack’. In computer science there are many data structures.
