DEV Community

Durga Pokharel
Durga Pokharel

Posted on

3

Day 48 Of 100DaysOfCode: Linked List

Today is my 48th day of 100daysOfCode and python learning. Today I learned about capstone: Retrieving, Processing, and Visualizing Data
from Coursera.

Also learned about linked list data structure in python. A linked list is a sequence of data elements, which are connected together through link.

Python Code

A linked list is created by using node class. We create a node object and create a another class to use this node object. We pass appropriate value through the node object to point to the next data elements.
python code is,

class Node:
    def __init__(self, dataval=None):
        self.dataval = dataval
        self.nextval = None

class SLinkedList:
    def __init__(self):
        self.headval = None

    def listprint(self):
        printval = self.headval
        while printval is not None:
            print (printval.dataval)
            printval = printval.nextval

list = SLinkedList()
list.headval = Node("Sun")
e2 = Node("Mon")
e3 = Node("Tue")
e4 = Node("Wed")
e5 = Node("Fri")
e6 = Node("Sat")


list.headval.nextval = e2
list.headval.nextval = e2
list.headval.nextval = e2
list.headval.nextval = e2


e2.nextval = e3
e3.nextval = e4
e4.nextval = e5
e5.nextval = e6

list.listprint()
Enter fullscreen mode Exit fullscreen mode

Output of the above program is

Sun
Mon
Tue
Wed
Fri
Sat

Enter fullscreen mode Exit fullscreen mode

Day 48 Of #100DaysOfCode and #Python
Linked list data structure in python#WomenWhoCode #DEVCommunity #100DaysOfCode #CodeNewbie #Python pic.twitter.com/ECZeM6c7yw

— Durga Pokharel (@mathdurga) February 10, 2021

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (1)

Collapse
 
otumianempire profile image
Michael Otu

52 days more..

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay