Movatterモバイル変換


[0]ホーム

URL:


Open In App

A linked list is a type of linear data structure individual items are not necessarily at contiguous locations. The individual items are called nodes and connected with each other using links.

Linked-list

Creating a Node Class

We have created a Node class in which we have defined a __init__ function to initialize the node with the data passed as an argument and a reference with None because if we have only one node then there is nothing in its reference.

Python
classNode:def__init__(self,data):self.data=dataself.next=None

Implementation of Simple 4 Nodes Linked List

Example: Below is a simple example to create a singly linked list with three nodes containing integer data.

Python
classNode:def__init__(self,data):self.data=dataself.next=None# Create nodesnode1=Node(15)node2=Node(3)node3=Node(17)node4=Node(90)# Link nodesnode1.next=node2node2.next=node3node3.next=node4head=node1# Head points to the first node# Traverse and print the linked listcurrent=headwhilecurrent:print(current.data,end=" -> ")current=current.nextprint("None")

Output
15 -> 3 -> 17 -> 90 -> None

Basics

Linked lists come in different forms depending on how nodes are connected. Each type has its own advantages and is used based on problem requirements. The main types of linked lists are:

To practice problems related to linked list, refer to this articleLinked List Data Structure


Improve
Improve
Article Tags :

Explore

Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp