Linked List
Linked List
Faculty of Engineering,
𝟐𝒏𝒅 Year Computer and Systems Department
Intro to Linked List:
A linked list is a linear data structure where elements (nodes) are
connected via pointers. Each node typically contains two parts:
1-Data: The value of the node.
2-Pointer: A reference to the next node (or null if it's the last node).
Linked lists are dynamic and allow efficient insertion and deletion,
making them suitable for scenarios where these operations are
frequent. They are preferred over arrays when the size of the data
structure needs to change dynamically or when memory fragmentation
is a concern.
*Example with Implementation:
Linked List:
#include <iostream>
using namespace std;
class Node {
public:
int data;
Node* next;
Node(int value) {
data = value;
next = nullptr;
}
};
class LinkedList {
public:
Node* head;
LinkedList() {
head = nullptr;
}