-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusing-linked-list.py
More file actions
31 lines (26 loc) · 745 Bytes
/
Copy pathusing-linked-list.py
File metadata and controls
31 lines (26 loc) · 745 Bytes
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
class Node:
def __init__(self, value, next_node=None):
self.value = value
self.next_node = next_node
class LinkedList:
def __init__(self):
self.head_node = None
def add_node(self, value):
if self.head_node:
new_node = Node(value, self.head_node)
self.head_node = new_node
else:
self.head_node = Node(value)
def values_as_list(self):
lst = []
current_node = self.head_node
while current_node:
lst.append(current_node.value)
current_node = current_node.next_node
return lst
x = LinkedList()
for char in "Hello, World!":
x.add_node(char)
y = x.values_as_list()
y.reverse()
print("".join(y))