Skip to content

Commit

Permalink
attempt 1
Browse files Browse the repository at this point in the history
  • Loading branch information
CScori committed May 21, 2020
1 parent 60fdb5e commit b5a1d61
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 12 deletions.
69 changes: 60 additions & 9 deletions doubly_linked_list/doubly_linked_list.py
Expand Up @@ -48,40 +48,91 @@ def __len__(self):
as the new head of the list. Don't forget to handle
the old head node's previous pointer accordingly."""
def add_to_head(self, value):
pass

# worry about head wory about no head
# wrap given val in Ln
new_node = ListNode(value, None, None)
# creatong a new node inst.
self.length += 1
# increaseses the length of dll
if self.head:
# checks if there was a head/ start of dll.
new_node.next = self.head
self.heaf.prev = new_node
self.head = new_node
else:
self.head = new_node
self.tail = new_node
"""Removes the List's current head node, making the
current head's next node the new head of the List.
Returns the value of the removed Node."""
def remove_from_head(self):
pass
value = self.head.value
self.delete(self.head)

return value


"""Wraps the given value in a ListNode and inserts it
as the new tail of the list. Don't forget to handle
the old tail node's next pointer accordingly."""
def add_to_tail(self, value):
pass
new_node = ListNode(value)
self.length += 1
self.tail = new_node
#there is a tail
if self.tail:
self.tail.next = new_node
new_node.prev = self.tail
# not a tail
else:
self.head = new_node
pass

"""Removes the List's current tail node, making the
current tail's previous node the new tail of the List.
Returns the value of the removed Node."""
def remove_from_tail(self):
pass




"""Removes the input node from its current spot in the
List and inserts it as the new head node of the List."""
def move_to_front(self, node):
pass

self.delete(node)
node.next = self.head
self.head.prev = node
self.head = node

"""Removes the input node from its current spot in the
List and inserts it as the new tail node of the List."""
def move_to_end(self, node):
pass

self.delete(node)
self.add_to_head(node)
"""Removes a node from the list and handles cases where
the node was the head or the tail"""
def delete(self, node):
pass

# if list is empty
if not self.head:
print('nothing to see here')
return

self.length -=1
# if one item
if self.head == self.tail:
self.head = None
self.tail = None


#more than 2 but delete is head
if node == self.head:
self.head = node.next
self.head.prev = None

else:
node.delete()

"""Returns the highest value currently in the list"""
def get_max(self):
Expand Down
21 changes: 18 additions & 3 deletions stack/stack.py
Expand Up @@ -10,16 +10,31 @@
3. What is the difference between using an array vs. a linked list when
implementing a Stack?
"""


class Stack:
def __init__(self):
stack = []
def __init__(self, size, value):
self.size = 0
# self.storage = ?

def __len__(self):
pass

def push(self, value):
pass
if self.size = -1:
self.stack.append(value)
elif len(self.stack) < self.size:
self.stack.append(value)
else:
print('cant add item')

def pop(self):
pass
if len(self.stac) > 0:
temp = self.stack[-1]
self.stack.pop()
return temp
else:
print('stack is already empty')


0 comments on commit b5a1d61

Please sign in to comment.