#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon May  4 10:03:28 2020

@author: TakahiroKurokawa
"""

class Stack:
    def __init__(self):
        self.items=[]
    
    def is_empty(self):
        return not self.items
    
    def push(self,item):
        self.items.append(item)
    
    def pop(self):
        return self.items.pop()
    
    def peek(self):
        return self.items[-1]
    
    def size(self):
        return len(self.items)

stack=Stack()
print(stack.is_empty())
stack.push(1)
print(stack.is_empty())

item=stack.pop()
print(item)
print(stack.is_empty())

for i in range(0,6):
    stack.push(i)

print(stack.peek())
print(stack.size())

stack=Stack()
for c in "Hello":
    stack.push(c)

reverse=[]
for x in range(len(stack.items)):
    a=stack.pop()
    reverse=reverse+[a]


class Queue:
    def __init__(self):
        self.items=[]
        
    def enqueue(self,item):
        self.items.insert(0,item)
        
    def dequeue(self):
        return self.items.pop(0)
    
    def is_empty(self):
        return not self.items
    
    def size(self):
        return len(self.items)

a_queue=Queue()
print(a_queue.is_empty())

for i in range(5):
    a_queue.enqueue(i)
    
while a_queue.size():
    print(a_queue.dequeue())


import time
import random
def simulate_line(till_show,max_time): 
    pq=Queue()
    tix_sold=[]    
    for i in range(100):
        pq.enqueue("person"+str(i))
    
    t_end=time.time()+till_show
    now=time.time()
    
    while now<t_end and not pq.is_empty:
        now=time.time()
        r=random.randint(0,max_time)
        time.sleep(r)
        person=pq.dequeue()
        print(person)
        tix_sold.append(person)
    return tix_sold

sold=simulate_line(5,1)
print(sold)    

stack=Stack()
for i in "yesterday":
    stack.push(i)
result=[]
for i in range(len(stack.items)):
    result+=[stack.pop()]

numbers=[1,2,3,4,5]
stack=Stack()
for i in numbers:
    stack.push(i)
result=[]
for i in range(len(stack.items)):
    result+=[stack.pop()]

