How is linked list implemented nodes structure referential structure?

Self Referential Structures

Self Referential structures are those structures that have one or more pointers which point to the same type of structure, as their member.

How is linked list implemented nodes structure referential structure?

In other words, structures pointing to the same type of structures are self-referential in nature.
Example:




struct node {

int data1;

char data2;

struct node* link;

};

int main()

{

struct node ob;

return 0;

}




class node:

def __init__(self):

self.data1=0

self.data2=''

self.link=None

if __name__ == '__main__':

ob=node()

In the above example ‘link’ is a pointer to a structure of type ‘node’. Hence, the structure ‘node’ is a self-referential structure with ‘link’ as the referencing pointer.
An important point to consider is that the pointer should be initialized properly before accessing, as by default it contains garbage value.
Types of Self Referential Structures



  1. Self Referential Structure with Single Link
  2. Self Referential Structure with Multiple Links

Self Referential Structure with Single Link: These structures can have only one self-pointer as their member. The following example will show us how to connect the objects of a self-referential structure with the single link and access the corresponding data members. The connection formed is shown in the following figure.

How is linked list implemented nodes structure referential structure?




#include <stdio.h>

struct node {

int data1;

char data2;

struct node* link;

};

int main()

{

struct node ob1; // Node1

// Initialization

ob1.link = NULL;

ob1.data1 = 10;

ob1.data2 = 20;

struct node ob2; // Node2

// Initialization

ob2.link = NULL;

ob2.data1 = 30;

ob2.data2 = 40;

// Linking ob1 and ob2

ob1.link = &ob2;

// Accessing data members of ob2 using ob1

printf("%d", ob1.link->data1);

printf("\n%d", ob1.link->data2);

return 0;

}




class node:

def __init__(self):

self.data1=0

self.data2=0

self.link=None

if __name__ == '__main__':

ob1=node() # Node1

# Initialization

ob1.link = None

ob1.data1 = 10

ob1.data2 = 20

ob2=node() # Node2

# Initialization

ob2.link = None

ob2.data1 = 30

ob2.data2 = 40

# Linking ob1 and ob2

ob1.link = ob2

# Accessing data members of ob2 using ob1

print(ob1.link.data1)

print(ob1.link.data2)

Output: 30 40

Self Referential Structure with Multiple Links: Self referential structures with multiple links can have more than one self-pointers. Many complicated data structures can be easily constructed using these structures. Such structures can easily connect to more than one nodes at a time. The following example shows one such structure with more than one links.
The connections made in the above example can be understood using the following figure.

How is linked list implemented nodes structure referential structure?




#include <stdio.h>

struct node {

int data;

struct node* prev_link;

struct node* next_link;

};

int main()

{

struct node ob1; // Node1

// Initialization

ob1.prev_link = NULL;

ob1.next_link = NULL;

ob1.data = 10;

struct node ob2; // Node2

// Initialization

ob2.prev_link = NULL;

ob2.next_link = NULL;

ob2.data = 20;

struct node ob3; // Node3

// Initialization

ob3.prev_link = NULL;

ob3.next_link = NULL;

ob3.data = 30;

// Forward links

ob1.next_link = &ob2;

ob2.next_link = &ob3;

// Backward links

ob2.prev_link = &ob1;

ob3.prev_link = &ob2;

// Accessing data of ob1, ob2 and ob3 by ob1

printf("%d\t", ob1.data);

printf("%d\t", ob1.next_link->data);

printf("%d\n", ob1.next_link->next_link->data);

// Accessing data of ob1, ob2 and ob3 by ob2

printf("%d\t", ob2.prev_link->data);

printf("%d\t", ob2.data);

printf("%d\n", ob2.next_link->data);

// Accessing data of ob1, ob2 and ob3 by ob3

printf("%d\t", ob3.prev_link->prev_link->data);

printf("%d\t", ob3.prev_link->data);

printf("%d", ob3.data);

return 0;

}




class node:

def __init__(self):

self.data=0

self.prev_link=None

self.next_link=None

if __name__ == '__main__':

ob1=node() #Node1

# Initialization

ob1.prev_link = None

ob1.next_link = None

ob1.data = 10

ob2=node() #Node2

# Initialization

ob2.prev_link = None

ob2.next_link = None

ob2.data = 20

ob3=node() # Node3

# Initialization

ob3.prev_link = None

ob3.next_link = None

ob3.data = 30

# Forward links

ob1.next_link = ob2

ob2.next_link = ob3

# Backward links

ob2.prev_link = ob1

ob3.prev_link = ob2

# Accessing data of ob1, ob2 and ob3 by ob1

print(ob1.data,end='\t')

print(ob1.next_link.data,end='\t')

print(ob1.next_link.next_link.data)

# Accessing data of ob1, ob2 and ob3 by ob2

print(ob2.prev_link.data,end='\t')

print(ob2.data,end='\t')

print(ob2.next_link.data)

# Accessing data of ob1, ob2 and ob3 by ob3

print(ob3.prev_link.prev_link.data,end='\t')

print(ob3.prev_link.data,end='\t')

print(ob3.data)

Output: 10 20 30 10 20 30 10 20 30

In the above example we can see that ‘ob1’, ‘ob2’ and ‘ob3’ are three objects of the self referential structure ‘node’. And they are connected using their links in such a way that any of them can easily access each other’s data. This is the beauty of the self referential structures. The connections can be manipulated according to the requirements of the programmer.
Applications:
Self referential structures are very useful in creation of other complex data structures like:

  • Linked Lists
  • Stacks
  • Queues
  • Trees
  • Graphs etc

How is linked list implemented nodes structure referential structure?




Article Tags :

Data Structures

Practice Tags :

Data Structures

Linked List Data Structure

  • Last Updated : 01 Feb, 2022

Practice Problems on Linked List
Recent Articles on Linked List

A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements in a linked list are linked using pointers as shown in the below image:

How is linked list implemented nodes structure referential structure?

In simple words, a linked list consists of nodes where each node contains a data field and a reference(link) to the next node in the list.

Topics :

  • Singly Linked List
  • Circular Linked List
  • Doubly Linked List

  • Misc
  • Quick Links

Singly Linked List :

  1. Introduction to Linked List
  2. Linked List vs Array
  3. Linked List Insertion
  4. Linked List Deletion (Deleting a given key)
  5. Linked List Deletion (Deleting a key at given position)
  6. Write a function to delete a Linked List
  7. Find Length of a Linked List (Iterative and Recursive)
  8. Search an element in a Linked List (Iterative and Recursive)
  9. Write a function to get Nth node in a Linked List
  10. Nth node from the end of a Linked List
  11. Print the middle of a given linked list
  12. Write a function that counts the number of times a given int occurs in a Linked List
  13. Detect loop in a linked list
  14. Find length of loop in linked list
  15. Function to check if a singly linked list is palindrome
  16. Remove duplicates from a sorted linked list
  17. Remove duplicates from an unsorted linked list
  18. Swap nodes in a linked list without swapping data
  19. Pairwise swap elements of a given linked list
  20. Move last element to front of a given Linked List
  21. Intersection of two Sorted Linked Lists
  22. Intersection point of two Linked Lists.
  23. QuickSort on Singly Linked List
  24. Segregate even and odd nodes in a Linked List
  25. Reverse a linked list

More >>

Circular Linked List :

  1. Circular Linked List Introduction and Applications,
  2. Circular Linked List Traversal
  3. Split a Circular Linked List into two halves
  4. Sorted insert for circular linked list
  5. Check if a linked list is Circular Linked List
  6. Convert a Binary Tree to a Circular Doubly Link List
  7. Circular Singly Linked List | Insertion
  8. Deletion from a Circular Linked List
  9. Circular Queue | Set 2 (Circular Linked List Implementation)
  10. Count nodes in Circular linked list
  11. Josephus Circle using circular linked list
  12. Convert singly linked list into circular linked list
  13. Circular Linked List | Set 1 (Introduction and Applications)
  14. Circular Linked List | Set 2 (Traversal)
  15. Implementation of Deque using circular array
  16. Exchange first and last nodes in Circular Linked List

More >>

Doubly Linked List :

  1. Doubly Linked List Introduction and Insertion
  2. Delete a node in a Doubly Linked List
  3. Reverse a Doubly Linked List
  4. The Great Tree-List Recursion Problem.
  5. Copy a linked list with next and arbit pointer
  6. QuickSort on Doubly Linked List
  7. Swap Kth node from beginning with Kth node from end in a Linked List
  8. Merge Sort for Doubly Linked List
  9. Create a Doubly Linked List from a Ternary Tree
  10. Find pairs with given sum in doubly linked list
  11. Insert value in sorted way in a sorted doubly linked list
  12. Delete a Doubly Linked List node at a given position
  13. Count triplets in a sorted doubly linked list whose sum is equal to a given value x
  14. Remove duplicates from a sorted doubly linked list
  15. Delete all occurrences of a given key in a doubly linked list
  16. Remove duplicates from an unsorted doubly linked list
  17. Sort the biotonic doubly linked list
  18. Sort a k sorted doubly linked list
  19. Convert a given Binary Tree to Doubly Linked List | Set
  20. Program to find size of Doubly Linked List
  21. Sorted insert in a doubly linked list with head and tail pointers
  22. Large number arithmetic using doubly linked list
  23. Rotate Doubly linked list by N nodes
  24. Priority Queue using doubly linked list
  25. Reverse a doubly linked list in groups of given size
  26. Doubly Circular Linked List | Set 1 (Introduction and Insertion)
  27. Doubly Circular Linked List | Set 2 (Deletion)

More >>

Misc :

  1. Skip List | Set 1 (Introduction)
  2. Skip List | Set 2 (Insertion)
  3. Skip List | Set 3 (Searching and Deletion)
  4. Reverse a stack without using extra space in O(n)
  5. An interesting method to print reverse of a linked list
  6. Linked List representation of Disjoint Set Data Structures
  7. Sublist Search (Search a linked list in another list)
  8. How to insert elements in C++ STL List ?
  9. Unrolled Linked List | Set 1 (Introduction)
  10. A Programmer’s approach of looking at Array vs. Linked List
  11. How to write C functions that modify head pointer of a Linked List?
  12. Given a linked list which is sorted, how will you insert in sorted way
  13. Can we reverse a linked list in less than O(n)?
  14. Practice questions for Linked List and Recursion
  15. Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
  16. Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?
  17. Why Quick Sort preferred for Arrays and Merge Sort for Linked Lists?
  18. Squareroot(n)-th node in a Linked List
  19. Find the fractional (or n/k – th) node in linked list
  20. Find modular node in a linked list
  21. Construct a linked list from 2D matrix
  22. Find smallest and largest elements in singly linked list
  23. Arrange consonants and vowels nodes in a linked list
  24. Partitioning a linked list around a given value and If we don’t care about making the elements of the list “stable”
  25. Modify contents of Linked List

Quick Links :

  • ‘Practice Problems’ on Linked List
  • ‘Videos’ on Linked List
  • ‘Quizzes’ on Linked List

If you still need more assistance with your placement preparation, have a look at our Complete Interview Preparation Course. The course has been designed by our expert mentors to help students crack the coding interview of top product or service-based organizations . You get access to premium lectures, 200+ coding questions bank, resume building tips, and lifetime access to the course content. So to make sure that your next programming interview doesn’t feel like an interrogation, enroll in Complete Interview Preparation and give a boost to your placement preparation.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

How is linked list implemented nodes structure referential structure?


Linked list Data Structure

In this tutorial, you will learn about linked list data structure and it's implementation in Python, Java, C, and C++.

A linked list is a linear data structure that includes a series of connected nodes. Here, each node stores the data and the address of the next node. For example,

How is linked list implemented nodes structure referential structure?
Linked list Data Structure

You have to start somewhere, so we give the address of the first node a special name called HEAD. Also, the last node in the linked list can be identified because its next portion points to NULL.

Linked lists can be of multiple types: singly, doubly, and circular linked list. In this article, we will focus on the singly linked list. To learn about other types, visit Types of Linked List.

Note: You might have played the game Treasure Hunt, where each clue includes the information about the next clue. That is how the linked list operates.


Linked List in A Data Structure: All You Need to Know

Lesson 3 of 54By Simplilearn

Last updated on Sep 19, 20216018

How is linked list implemented nodes structure referential structure?

PreviousNext

  • Tutorial Playlist

    Data Structure Tutorial

    Overview

    Arrays in Data Structures: A Guide With Examples

    Lesson - 1

    All You Need to Know About Two-Dimensional Arrays

    Lesson - 2

    All You Need to Know About a Linked List in a Data Structure

    Lesson - 3

    The Complete Guide to Implement a Singly Linked List

    Lesson - 4

    The Ultimate Guide to Implement a Doubly Linked List

    Lesson - 5

    The Fundamentals for Understanding Circular Linked List

    Lesson - 6

    The Ultimate Guide To Understand The Differences Between Stack And Queue

    Lesson - 7

    Implementing Stacks in Data Structures

    Lesson - 8

    Your One-Stop Solution for Stack Implementation Using Array

    Lesson - 9

    Your One-Stop Solution for Queue Implementation Using Array

    Lesson - 10

    Your One-Stop Solution to Learn Depth-First Search(DFS) Algorithm From Scratch

    Lesson - 11

    Your One-Stop Solution for Stack Implementation Using Linked-List

    Lesson - 12

    The Definitive Guide to Understand Stack vs Heap Memory Allocation

    Lesson - 13

    All You Need to Know About Linear Search Algorithm

    Lesson - 14

    All You Need to Know About Breadth-First Search Algorithm

    Lesson - 15

    A One-Stop Solution for Using Binary Search Trees in Data Structure

    Lesson - 16

    The Best Tutorial to Understand Trees in Data Structure

    Lesson - 17

    A Complete Guide to Implement Binary Tree in Data Structure

    Lesson - 18

    A Holistic Look at Using AVL Trees in Data Structures

    Lesson - 19

    All You Need to Know About Tree Traversal in Data Structure

    Lesson - 20

    The Best Guide You’ll Ever Need to Understand B-Tree in Data Structure

    Lesson - 21

    The Best Guide You'll Ever Need to Understand Spanning Tree in Data Structure

    Lesson - 22

    The Best and Easiest Way to Understand an Algorithm

    Lesson - 23

    Your One-Stop Solution to Understand Shell Sort Algorithm

    Lesson - 24

    Your One-Stop Solution to Quick Sort Algorithm

    Lesson - 25

    The Most Useful Guide to Learn Selection Sort Algorithm

    Lesson - 26

    Everything You Need to Know About Radix Sort Algorithm

    Lesson - 27

    Everything You Need to Know About the Counting Sort Algorithm

    Lesson - 28

    Everything You Need to Know About the Merge Sort Algorithm

    Lesson - 29

    Insertion Sort Algorithm: One-Stop Solution That Will Help You Understand Insertion Sort

    Lesson - 30

    Everything You Need to Know About the Bubble Sort Algorithm

    Lesson - 31

    The Best Guide You’ll Ever Need to Understand Bucket Sort Algorithm

    Lesson - 32

    Your One-Stop Solution to Understand Recursive Algorithm in Programming

    Lesson - 33

    The Definitive Guide to Understanding Greedy Algorithm

    Lesson - 34

    Your One-Stop Solution to Understand Backtracking Algorithm

    Lesson - 35

    The Fundamentals of the Bellman-Ford Algorithm

    Lesson - 36

    Your One-Stop Solution for Graphs in Data Structures

    Lesson - 37

    The Best Guide to Understand and Implement Solutions for Tower of Hanoi Puzzle

    Lesson - 38

    A Simplified and Complete Guide to Learn Space and Time Complexity

    Lesson - 39

    All You Need to Know About the Knapsack Problem : Your Complete Guide

    Lesson - 40

    The Fibonacci Series: Mathematical and Programming Interpretation

    Lesson - 41

    The Holistic Look at Longest Common Subsequence Problem

    Lesson - 42

    The Best Article to Understand What Is Dynamic Programming

    Lesson - 43

    A Guide to Implement Longest Increasing Subsequence Using Dynamic Programming

    Lesson - 44

    A Holistic Guide to Learn Stop Solution Using Dynamic Programming

    Lesson - 45

    One Stop Solution to All the Dynamic Programming Problems

    Lesson - 46

    Understanding the Fundamentals of Binomial Distribution

    Lesson - 47

    Here’s All You Need to Know About Minimum Spanning Tree in Data Structures

    Lesson - 48

    Understanding the Difference Between Array and Linked List

    Lesson - 49

    The Best Article Out There to Understand the B+ Tree in Data Structure

    Lesson - 50

    A Comprehensive Look at Queue in Data Structure

    Lesson - 51

    Your One-Stop Solution to Understand Coin Change Problem

    Lesson - 52

    The Best Way to Understand the Matrix Chain Multiplication Problem

    Lesson - 53

    Your One-Stop Solution to Learn Floyd-Warshall Algorithm for Using Dynamic Programming

    Lesson - 54

Table of Contents

View More

A linked list is the most sought-after data structure when it comes to handling dynamic data elements. A linked list consists of a data element known as a node. And each node consists of two fields: one field has data, and in the second field, the node has an address that keeps a reference to the next node.

What is a Linked List?

  • A linked list is a linear data structure that stores a collection of data elements dynamically.
  • Nodes represent those data elements, and links or pointers connect each node.
  • Each node consists of two fields, the information stored in a linked list and a pointer that stores the address of its next node.
  • The last node contains null in its second field because it will point to no node.
  • A linked list can grow and shrink its size, as per the requirement.
  • It does not waste memory space.

Post Graduate Program in Data Analytics

In partnership with Purdue UniversityView Course

How is linked list implemented nodes structure referential structure?