Facebook
From Big Hog, 3 Years ago, written in Python.
This paste is a reply to Untitled from Ample Cockroach - view diff
Embed
Download Paste or View Raw
Hits: 68
  1. class Node:
  2.     def __init__(self,addr):
  3.         self.addr=addr
  4.         self.next=None
  5.         self.back=None
  6.    
  7. class WebBrowser2:
  8.  
  9.  
  10.     def __init__(self):
  11.         self.homeAddr = 'www.hufs.ac.kr'
  12.         self.head = Node(self.homeAddr)
  13.         self.tail=Node(None)
  14.         self.head.back=None
  15.         self.head.next=self.tail
  16.         self.tail.back=self.head
  17.         self.tail.next=None
  18.         self.current = self.head
  19.  
  20.  
  21.  
  22.     def forward(self):
  23.         if self.current.next is not None:
  24.             self.current=self.current.next
  25.             print(self.current.addr)
  26.        
  27.  
  28.     def backward(self):
  29.         if self.current!=self.head:
  30.             self.current=self.current.back
  31.             print(self.current.addr)
  32.            
  33.     def go(self,addr):
  34.         location=Node(addr)
  35.         self.current.next=location
  36.         location.back=self.current
  37.         self.current=location
  38.         print(addr)
  39.  
  40.  
  41.        
  42.     def history(self):
  43.         location=self.current
  44.         while location is not None:
  45.             self.current.next=location
  46.             location.back=self.current
  47.             location=self.current.next
  48.         while location is self.head:
  49.             print(location.addr)
  50.             location=location.back
  51.        
  52.         '''
  53.        node=self.tail
  54.        while node is self.head:
  55.            print(node.addr)
  56.            node=node.back
  57.           '''
  58.         '''
  59.        result=[]
  60.        cur=self.tail
  61.        while cur.back.back:
  62.            cur=cur.back
  63.            result.append(cur.addr)
  64.        print(result)
  65.        '''
  66.         '''
  67.        ptr=self.head.back
  68.        while ptr is not self.head:
  69.            print(ptr.addr)
  70.            prt=ptr.back
  71.            
  72.         '''  
  73.         '''
  74.        while node is not None:
  75.            print(node.addr)
  76.            node=node.next
  77.             '''
  78.  
  79.        
  80.            
  81.            
  82. w=WebBrowser2()
  83.  
  84. command=[]
  85. while True:
  86.     A=input()
  87.     if A=='quit':break
  88.     command.append(A.split())
  89. n=len(command)
  90.  
  91. print(w.homeAddr)
  92.  
  93. for i in range(n):
  94.  
  95.     if(command[i][0]=='forward'):
  96.         w.forward()
  97.     elif command[i][0]=='backward':
  98.         w.backward()
  99.     elif command[i][0]=='go':
  100.         w.go(command[i][1])
  101.     elif command[i][0]=='history':
  102.         w.history()
  103.