Linked_List_Types_Notes
Linked_List_Types_Notes
Definition:
A linear data structure where each node points to the next node.
class SinglyLinkedList {
Node* head;
public:
SinglyLinkedList() { head = nullptr; }
void insertFront(int val) { ... }
void insertEnd(int val) { ... }
void deleteNode(int val) { ... }
void display() { ... }
};
Definition:
Each node points to both the next and previous node.
Code:
class Node {
public:
int data;
Node* prev;
Node* next;
Node(int val) { data = val; prev = next = nullptr; }
};
class DoublyLinkedList {
Node* head;
public:
DoublyLinkedList() { head = nullptr; }
void insertFront(int val) { ... }
void insertEnd(int val) { ... }
void deleteNode(int val) { ... }
void displayForward() { ... }
void displayBackward() { ... }
};
Linked Lists: Types and C++ Implementations
Definition:
Last node points back to the first node.
Code:
class Node {
public:
int data;
Node* next;
Node(int val) { data = val; next = nullptr; }
};
class CircularSinglyLinkedList {
Node* head;
public:
CircularSinglyLinkedList() { head = nullptr; }
void insertEnd(int val) { ... }
void deleteNode(int val) { ... }
void display() { ... }
};
Definition:
Last node points to the first and first node points to the last.
Code:
class Node {
public:
int data;
Node* prev;
Node* next;
Node(int val) { data = val; prev = next = nullptr; }
};
class CircularDoublyLinkedList {
Node* head;
public:
CircularDoublyLinkedList() { head = nullptr; }
void insertEnd(int val) { ... }
void deleteNode(int val) { ... }
void displayForward() { ... }
};