Created
June 19, 2015 14:24
-
-
Save wmantly/c354745af31d4bc8d5d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| class Node: | |
| def __init__( self, data , point ): | |
| self.data = data | |
| self.point = point | |
| class LinkedList: | |
| def __init__( self, data ): | |
| temp = Node( data, None ) | |
| self.head = temp | |
| self.last = temp | |
| def search( self, search = None): | |
| out = [] | |
| before = self.head | |
| node = self.head | |
| node = node.point | |
| while True: | |
| print( node.data ) | |
| if search != None and search == node.data: | |
| print("found!") | |
| out.append( node.data ) | |
| if node.point == None: | |
| break | |
| node = node.point | |
| if len(out): return False | |
| return out | |
| def prepend( self, data ): | |
| self.head = Node( data, self.head ) | |
| def append( self, data ): | |
| self.last = Node( data, None ) | |
| # def insert( self ): | |
| pass | |
| def delete( self, search ): | |
| before = self.head | |
| node = self.head | |
| while True: | |
| if search != None and search == node.data: | |
| before.point = node.point | |
| return node | |
| if node.point == None: | |
| break | |
| before = node | |
| node = node.point | |
| return False; | |
| # def pop( self ): | |
| # def shift( self ): | |
| link = LinkedList('test1') | |
| link.prepend('test2') | |
| link.prepend('test3') | |
| link.prepend('test4') | |
| link.prepend('test5') | |
| link.prepend('test6') | |
| print("=============") | |
| # print( link.head.head.head ) | |
| #link.delete('test4') | |
| print( link.search() ) | |
| #link.search('test3') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment