<s> __author__ = "<STR_LIT>" <EOL> '''<STR_LIT>''' <EOL> from node import Node <EOL> class LinkedListFIFO ( object ) : <EOL> def __init__ ( self ) : <EOL> self . head = None <EOL> self . length = <NUM_LIT:0> <EOL> self . tail = None <EOL> def _printList ( self ) : <EOL> node = self . head <EOL> while node : <EOL> print ( node . value ) <EOL> node = node . pointer <EOL> def _addFirst ( self , value ) : <EOL> self . length = <NUM_LIT:1> <EOL> node = Node ( value ) <EOL> self . head = node <EOL> self . tail = node <EOL> def _deleteFirst ( self ) : <EOL> self . length = <NUM_LIT:0> <EOL> self . head = None <EOL> self . tail = None <EOL> print ( '<STR_LIT>' ) <EOL> def _add ( self , value ) : <EOL> self . length += <NUM_LIT:1> <EOL> node = Node ( value ) <EOL> if self . tail : <EOL> self . tail . pointer = node <EOL> self . tail = node <EOL> def addNode ( self , value ) : <EOL> if not self . head : <EOL> self . _addFirst ( value ) <EOL> else : <EOL> self . _add ( value ) <EOL> def _find ( self , index ) : <EOL> prev = None <EOL> node = self . head <EOL> i = <NUM_LIT:0> <EOL> while node and i < index : <EOL> prev = node <EOL> node = node . pointer <EOL> i += <NUM_LIT:1> <EOL> return node , prev , i <EOL> def deleteNode ( self , index ) : <EOL> if not self . head or not self . head . pointer : <EOL> self . _deleteFirst ( ) <EOL> else : <EOL> node , prev , i = self . _find ( index ) <EOL> if i == index and node : <EOL> self . length -= <NUM_LIT:1> <EOL> if i == <NUM_LIT:0> or not prev : <EOL> self . head = node . pointer <EOL> else : <EOL> prev . pointer = node . pointer <EOL> if not self . tail == node : <EOL> self . tail = prev <EOL> else : <EOL> print ( '<STR_LIT>' . format ( index ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> ll = LinkedListFIFO ( ) <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:5> ) : <EOL> ll . addNode ( i ) <EOL> print ( '<STR_LIT>' ) <EOL> ll . _printList ( ) <EOL> print ( '<STR_LIT>' ) <EOL> ll . deleteNode ( <NUM_LIT:2> ) <EOL> ll . _printList ( ) <EOL> print ( '<STR_LIT>' ) <EOL> ll . _add ( <NUM_LIT:15> ) <EOL> ll . _printList ( ) <EOL> print ( "<STR_LIT>" ) <EOL> for i in range ( ll . length - <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> ll . deleteNode ( i ) <EOL> ll . _printList ( ) </s>
