Skip to content

Commit 40693fa

Browse files
added linkedlist abstract method (#223)
Co-authored-by: Harsheet-saxena <harshsaxena1999@gmail.com>
1 parent 571dcd1 commit 40693fa

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

pydatastructs/linear_data_structures/linked_lists.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,66 @@ def __str__(self):
4343
break
4444
return str(elements)
4545

46+
def insert_after(self, prev_node, key, data=None):
47+
"""
48+
Inserts a new node after the prev_node.
49+
50+
Parameters
51+
==========
52+
53+
prev_node: LinkedListNode
54+
The node after which the
55+
new node is to be inserted.
56+
57+
data
58+
Any valid data to be stored in the node.
59+
"""
60+
raise NotImplementedError('This is an abstract method')
61+
62+
def insert_at(self, index, key, data=None):
63+
"""
64+
Inserts a new node at the input index.
65+
66+
Parameters
67+
==========
68+
69+
index: int
70+
An integer satisfying python indexing properties.
71+
72+
data
73+
Any valid data to be stored in the node.
74+
"""
75+
raise NotImplementedError('This is an abstract method')
76+
77+
def extract(self, index):
78+
"""
79+
Extracts the node at the index of the list.
80+
81+
Parameters
82+
==========
83+
84+
index: int
85+
An integer satisfying python indexing properties.
86+
87+
Returns
88+
=======
89+
90+
current_node: LinkedListNode
91+
The node at index i.
92+
"""
93+
raise NotImplementedError('This is an abstract method')
94+
95+
def __getitem__(self, index):
96+
"""
97+
Returns
98+
=======
99+
100+
current_node: LinkedListNode
101+
The node at given index.
102+
"""
103+
raise NotImplementedError('This is an abstract method')
104+
105+
46106
class DoublyLinkedList(LinkedList):
47107
"""
48108
Represents Doubly Linked List

0 commit comments

Comments
 (0)