Facebook
From Big Hog, 3 Years ago, written in Python.
This paste is a reply to Untitled from Ample Cockroach - go back
Embed
Viewing differences between Untitled and Re: Untitled
\nclass Node:
    def __init__(self,addr):
        self.addr=addr
        self.next=None
        self.back=None
    
class WebBrowser2:


    def __init__(self):
        self.homeAddr = 'www.hufs.ac.kr'
        self.head = Node(self.homeAddr)
        self.tail=Node(None)
        self.head.back=None
        self.head.next=self.tail
        self.tail.back=self.head
        self.tail.next=None
        self.current = self.head


 
    def forward(self):
        if self.current.next is not None:
            self.current=self.current.next
            print(self.current.addr)
       

    def backward(self):
        if self.current!=self.head:
            self.current=self.current.back
            print(self.current.addr)
            
    def go(self,addr):
        location=Node(addr)
        self.current.next=location
        location.back=self.current
        self.current=location
        print(addr)


        
    def history(self):
        location=self.current
        while location is not None:
            self.current.next=location
            location.back=self.current
            location=self.current.next
        while location is self.head:
            print(location.addr)
            location=location.back
        
        '''
        node=self.tail
        while node is self.head:
            print(node.addr)
            node=node.back
            \n           ''' 
        '''
        result=[]
        cur=self.tail
        while cur.back.back:
            cur=cur.back
            result.append(cur.addr)
        print(result)
        '''
        '''
        ptr=self.head.back
        while ptr is not self.head:
            print(ptr.addr)
            prt=ptr.back
            
         '''   
        '''
        while node is not None:
            print(node.addr)
            node=node.next
             '''

        
            
            
w=WebBrowser2()

command=[]
while True:
    A=input()
    if A=='quit':break
    command.append(A.split())
n=len(command)

print(w.homeAddr)

for i in range(n):

    if(command[i][0]=='forward'):
        w.forward()
    elif command[i][0]=='backward':
        w.backward()
    elif command[i][0]=='go':
        w.go(command[i][1])
    elif command[i][0]=='history':
        w.history()