Advertisement
Guest User

Untitled

a guest
Sep 9th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. class Stack:
  2.  
  3.     class StackNode:
  4.  
  5.         def __init__(self, value):
  6.             self.value = value
  7.             self.next = None
  8.  
  9.  
  10.     def __init__(self):
  11.         self.head = None
  12.  
  13.  
  14.     def add(self, value):
  15.         if self.head is None:
  16.             self.head = self.StackNode(value)
  17.             return
  18.  
  19.         current = self.head
  20.         while current.next is not None:
  21.             current = current.next
  22.  
  23.         current.next = self.StackNode(value)
  24.  
  25.  
  26.     def remove(self, value):
  27.         if self.head is None:
  28.             return
  29.  
  30.         self.head = self.head.next
  31.  
  32.  
  33.     def peek(self):
  34.         return self.head
  35.  
  36.  
  37.     def is_empty(self):
  38.         return self.head is None
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement