forked from abhaysamantni/Python_MidTerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Midterm_Review_Q9.py
27 lines (22 loc) · 881 Bytes
/
Midterm_Review_Q9.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
#Practice for linked list. No specific question, just a practice and review code
# A linked list is a sequence of data elements, which are connected together via links. Each data element contains a
# connection to
# another data element in form of a pointer. Python does not have linked lists in its standard library.
#
# See code below to understand how to create a node class and use this to create a singly linked lists.
# In this type of data structure there is only one link between any two data elements.
class Node:
def __init__(self, dataval=None):
self.dataval = dataval
self.nextval = None
class SLinkedList:
def __init__(self):
self.headval = None
list1 = SLinkedList()
list1.headval = Node("Mon")
e2 = Node("Tue")
e3 = Node("Wed")
# Link first Node to second node
list1.headval.nextval = e2
# Link second Node to third node
e2.nextval = e3