Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Overig

Operations on Linked Lists: Insertion, Deletion, and Traversal

Beoordeling
-
Verkocht
-
Pagina's
7
Geüpload op
28-01-2025
Geschreven in
2024/2025

This document covers the essential operations on linked lists, including insertion, deletion, and traversal techniques for singly and doubly linked lists, explained with practical examples and code snippets.

Instelling
Vak

Voorbeeld van de inhoud

Operations on Linked Lists
Linked lists support several essential operations that allow you to manipulate the
data in the list. These operations vary depending on the type of linked list (singly,
doubly, or circular). Below are some of the most common operations on linked
lists.



1. Basic Operations
1.1 Traversal

Traversal refers to the process of visiting each node in the linked list. This
operation is typically used to display all elements of the list or search for a
particular element.

 Singly Linked List: Start from the head and follow the next pointers until
reaching null.
 Doubly Linked List: Traverse from the head to the last node and back using
both next and prev pointers.
 Circular Linked List: Traverse starting from the head and continue until
reaching the head again.

Example (Python - Singly Linked List):

def traverse(self):
current = self.head
while current:
print(current.data, end=" -> ")
current = current.next
print("None")


1.2 Insertion

Insertion involves adding a new node at a specific position in the linked list.
Common insertion operations include:

,  At the beginning: Insert the node at the head of the list.
 At the end: Insert the node at the last position.
 At a specific position: Insert the node at a given index.

Example (Python - Insert at the Beginning for Singly Linked List):

def insert_at_beginning(self, data):
new_node = Node(data)
new_node.next = self.head
self.head = new_node

Insert at the End for Singly Linked List:

def insert_at_end(self, data):
new_node = Node(data)
if not self.head:
self.head = new_node
return
current = self.head
while current.next:
current = current.next
current.next = new_node


1.3 Deletion

Deletion involves removing a node from the linked list. The most common
deletions are:

 Delete from the beginning: Remove the head node.
 Delete from the end: Remove the last node.
 Delete by value: Remove a specific node containing a given value.
 Delete by position: Remove the node at a specific index.

Example (Python - Delete from the Beginning for Singly Linked List):

def delete_from_beginning(self):
if self.head:
self.head = self.head.next

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
28 januari 2025
Aantal pagina's
7
Geschreven in
2024/2025
Type
OVERIG
Persoon
Onbekend

Onderwerpen

€5,88
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
rileyclover179

Ook beschikbaar in voordeelbundel

Maak kennis met de verkoper

Seller avatar
rileyclover179 US
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
-
Lid sinds
1 jaar
Aantal volgers
0
Documenten
252
Laatst verkocht
-

0,0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Populaire documenten

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen