Difference between revisions of "Stacks"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Push)
Line 2: Line 2:
 
The stack has limited size and the stack pointed will always point to the value at the top of the stack. An empty stack thus has a stack pointer value of 0. You can only push an item if the stack is not full. You can only pop an item if the stack is not empty.
 
The stack has limited size and the stack pointed will always point to the value at the top of the stack. An empty stack thus has a stack pointer value of 0. You can only push an item if the stack is not full. You can only pop an item if the stack is not empty.
 
==Push==
 
==Push==
 +
When an item is pushed it is added to the back of the queue, so if bob is at value one. And Bill is pushed, he would be added to value 2.
 +
 
==Pop==
 
==Pop==
 
==Peek==
 
==Peek==

Revision as of 08:49, 16 May 2017

A stack is a data structure that can only have data added or removed from the top. The stack has limited size and the stack pointed will always point to the value at the top of the stack. An empty stack thus has a stack pointer value of 0. You can only push an item if the stack is not full. You can only pop an item if the stack is not empty.

Push

When an item is pushed it is added to the back of the queue, so if bob is at value one. And Bill is pushed, he would be added to value 2.

Pop

Peek