Lab4 LinkedList Doubly Circular
Lab4 LinkedList Doubly Circular
Section/Lab Objective
This lab is designed to give an overview about double and circular linked list supported with
practical examples.
Singly linked list (Already taught in the previous section): Singly linked lists contain nodes which
have a data field as well as a next field, which points to the next node in line of
nodes.
Doubly linked list: In a doubly linked list, each node contains, besides the next the previous node in the
sequence. The two links may be called forward(s) and backwards, or next and prev(previous).
Circular list: In the last node of a list, the link field often contains a null reference, a special value used to
indicate the lack of further nodes. A less common convention is to make it point to the first node of the list; in
that case the list is said 'circular' or 'circularly linked'; otherwise it is said to be 'open' or 'linear'.
Linked List
In the case of a circular doubly linked list, the only change that occurs is that the end, or "tail", of the said list is lin
to the front, or "head", of the list and vice versa.
Cairo University
Faculty of Computer Science and Artificial Intelligence
Data Structures, 2nd Term, 2023
struct Node {
int value;
Node *next;
Node *previous;
Node(){
value = 0;
next = nullptr;
previous = nullptr;
};
- tail that holds the address of the last Node, it would be Null if the list is empty.
class DoublyLinkedList {
private:
int size;
Node *head;
Node *tail;
public:
DoublyLinkedList(){
head = nullptr;
tail = nullptr;
size = 0;
Task 1:
Implement member function remove for your double linked list class. Remove takes an
element, search for it, if found it will remove it from the list.
Cairo University
Faculty of Computer Science and Artificial Intelligence
Data Structures, 2nd Term, 2023
Task 2:
Given a null-terminated doubly linked list, reverse the order of its nodes. Do not allocate any new
nodes in the list.
Hint: you will use two pointers, one to iterate and one for swapping
void DLL<T>::reverse();