forked from HU-CS201-master/hw01-spring-18
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdl_list.py
89 lines (67 loc) · 2.05 KB
/
dl_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class DLNode:
def __init__(self, data):
self.data = data
self.front = self.back = None
def __str__(self):
'''Returns a string representation of an object for printing.
'''
pass
class DLList:
def __init__(self):
'''Initializes the dummy node and size.'''
pass
def __str__(self):
'''Returns a string representation of an object for printing.
'''
pass
def get(self, i):
'''DL.get(int) -> value
Returns the value stored at index, i.
Returns None if i \notin {-n, ... , n-1}.
Runs in O(1 + min(i, n-i)) time.
'''
pass
def set(self, i, x):
'''DL.set(int, value) -> bool
Sets the element at index, i, to x and returns True.
Returns False if i \notin {-n, ... , n-1}.
Runs in O(1 + min(i, n-i)) time.
'''
pass
def add(self, i, x):
'''DL.add(int, value) -> bool
Inserts x at index, i, and returns True.
Returns False if i \notin {0, ... , n}.
Runs in O(1 + min(i, n-i)) time.
'''
pass
def remove(self, i):
'''DL.remove(int) -> value
Removes the element at index, i, and returns it.
Returs None if i \notin {0, ... , n-1}.
Runs in O(1 + min(i, n-i)) time.
'''
pass
'''The next few methods involve performing manipulations on
DLLists. You should complete them without allocating any new nodes
or temporary arrays. They can all be done only by changing the
value of front and back in existing nodes.
'''
def is_palindrome(self):
'''As described in Exercise 3.7.
'''
pass
def truncate(self):
'''As described in Exercise 3.9.
'''
pass
def absorb(self):
'''As described in Exercise 3.10.
Your code should run in O(1) time.
'''
pass
def reverse(self):
'''As described in Exercise 3.12.
Your code should run in O(n) time.
'''
pass