Skip to content

Commit fe60f2c

Browse files
committed
added comments to code
1 parent bfcabb4 commit fe60f2c

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

BrowserHistory/backend.py

+36-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
class DLL:
2+
"""
3+
a doubly linked list that holds the current page,
4+
next page, and previous page.
5+
Used to enforce order in operations
6+
"""
27
def __init__(self, val: str =None):
38
self.val = val
49
self.nxt = None
@@ -7,15 +12,30 @@ def __init__(self, val: str =None):
712

813
class BrowserHistory:
914
"""
10-
This class designs the operations of a
11-
broswer history
15+
This class designs the operations of a browser history
16+
17+
It works by using a doubly linked list to hold the urls
1218
"""
1319

1420
def __init__(self, homepage: str):
21+
"""
22+
Returns - None
23+
Input - None
24+
----------
25+
- Initialize doubly linked list which will serve as the
26+
browser history and sets the current page
27+
"""
1528
self.head = DLL(homepage)
1629
self.curr = self.head
1730

1831
def visit(self, url: str) -> None:
32+
"""
33+
Returns - None
34+
Input - str
35+
----------
36+
- Adds the current url to the DLL
37+
- sets both the next and previous values
38+
"""
1939
url_node = DLL(url)
2040
self.curr.nxt = url_node
2141
url_node.prev = self.curr
@@ -24,13 +44,27 @@ def visit(self, url: str) -> None:
2444

2545

2646
def back(self, steps: int) -> str:
47+
"""
48+
Returns - str
49+
Input - int
50+
----------
51+
- Iterates through the DLL backwards `step` number of times
52+
- returns the appropriate value
53+
"""
2754
while steps > 0 and self.curr.prev:
2855
self.curr = self.curr.prev
2956
steps -= 1
3057
return self.curr.val
3158

3259

3360
def forward(self, steps: int) -> str:
61+
"""
62+
Returns - str
63+
Input - int
64+
----------
65+
- Iterates through the DLL forewards `step` number of times
66+
- returns the appropriate value
67+
"""
3468
while steps > 0 and self.curr.nxt:
3569
self.curr = self.curr.nxt
3670
steps -= 1

0 commit comments

Comments
 (0)