From 4eddeb93964400cecbca44cc9b44994fe0eda70a Mon Sep 17 00:00:00 2001 From: James Mc Dermott Date: Fri, 14 Oct 2016 16:15:26 +0100 Subject: [PATCH] Create __init__.py Initialising of a Stack Class, has three methods: is_empty, push and pop. --- data_structures/Stacks/__init__.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 data_structures/Stacks/__init__.py diff --git a/data_structures/Stacks/__init__.py b/data_structures/Stacks/__init__.py new file mode 100644 index 000000000..1c6488562 --- /dev/null +++ b/data_structures/Stacks/__init__.py @@ -0,0 +1,23 @@ +class Stack: + + def __init__(self): + self.stack = [] + self.top = 0 + + def is_empty(self): + return self.top == 0 + + def push(self, item): + if self.top < len(self.stack): + self.stack[self.top] = item + else: + self.stack.append(item) + + self.top += 1 + + def pop(self): + if self.is_empty(): + return None + else: + self.top -= 1 + return self.stack[self.top]