Skip to content

Instantly share code, notes, and snippets.

@papousek
Last active December 28, 2015 10:09
Show Gist options
  • Save papousek/7484156 to your computer and use it in GitHub Desktop.
Save papousek/7484156 to your computer and use it in GitHub Desktop.

Datové struktury - fronta a zásobník

V případě zásobníku lze použít již známý list, viz dokumentace.

>>> stack = [3, 4, 5]                                                                               
>>> stack.append(6)                                                                                 
>>> stack.append(7)                                                                                 
>>> stack                                                                                           
[3, 4, 5, 6, 7]                                                                                     
>>> stack.pop()                                                                                     
7                                                                                                   
>>> stack                                                                                           
[3, 4, 5, 6]                                                                                        
>>> stack.pop()                                                                                     
6                                                                                                   
>>> stack.pop()                                                                                     
5                                                                                                   
>>> stack                                                                                           
[3, 4]                                                                                              

V případě fronty je nutné použít modul collections, viz dokumentace.

>>> from collections import deque                                                                   
>>> queue = deque(["Eric", "John", "Michael"])                                                      
>>> queue.append("Terry")           # Terry arrives                                                 
>>> queue.append("Graham")          # Graham arrives                                                
>>> queue.popleft()                 # The first to arrive now leaves                                
'Eric'                                                                                              
>>> queue.popleft()                 # The second to arrive now leaves                               
'John'                                                                                              
>>> queue                           # Remaining queue in order of arrival                           
deque(['Michael', 'Terry', 'Graham'])                                                               

Logické výrazy

Napište funkci, která vyhodnotí logický výrok zapsaný v postfixové notaci.

# Vrati True, pokud se dany vyrok vyhodnoti jako pravdivy,                                          
# jinak False. Vyrok se sklada z nasledujícich znaku:                                               
# - 'N': negace                                                                                     
# - 'K': konjunkce                                                                                  
# - 'A': disjunkce                                                                                  
# - 'C': implikace                                                                                  
#                                                                                                   
# Priklad volání:                                                                                   
# >>> eval_postfix("FNTFCNK")                                                                       
#                                                                                                   
# True                                                                                              
def eval_postfix(term):                                                                             
  pass                                                                                              
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment