A header file that as number of pre loaded methods on doubly linked list
Download the doublyLinkedList.h header file and paste it into your source code folder and then write this in your .cpp file
#include "doublyLinkedList.h"
Note - All Function are made with single data in mind , you have to change the struct node and add more data operations in the doublyLinkedList.h according to your use
DoublyLinkedList dl;
node *head = dl.generateHead(10);
Now you can display every element in the linked list by passing this head pointer to this function
string seperator = ","
displayFromHead_doublyLinkedList(head , seperator)
let Head be the pointer to the linked list
// function to add to the beginning of the doubly linked list
void addToBeginning_doublyLinkedList(node* &head , int data)
// function to display elements
// pass the head of the linked list
// things will be seperated by the string seperator
void displayFromHead_doublyLinkedList(node* head , string seperator = " ")
// function to display elements
// pass the tail of the linked list
// things will be seperated by the string seperator
void displayFromTail_doublyLinkedList(node* tail , string seperator = " ")
// function to find the size of linked list
// keep one NULL and pass the value of other
int size_doublyLinkedList(node* head = NULL , node* tail = NULL)
#include<iostream>
#include<conio.h>
#include "doublyLinkedList.h"
using namespace std;
void doublyLinkedList()
{
DoublyLinkedList dl;
node *head = dl.generateHead(10);
cout<<"initialLinkedList"<<endl;
displayFromHead_doublyLinkedList(head);
addToBeginning_doublyLinkedList(head, 29);
cout<<"\nafter adding 29 to start"<<endl;
displayFromHead_doublyLinkedList(head);
addToBeginning_doublyLinkedList(head, 58);
cout<<"\nafter adding 58 to start"<<endl;
displayFromHead_doublyLinkedList(head);
cout<<"\nsize by passing head = "<<size_doublyLinkedList(head)<<endl;
}
int main()
{
doublyLinkedList();
getch();
return 0;
}