Professional Documents
Culture Documents
1. Aim/Overview of the practical: Code to Insert and Delete an element at the beginning and
at end in Doubly and Circular Linked List.
2. Task to be done/ Which logistics used: The task is to create a function which will insert and
delete elements at the beginning and end in doubly and circular linked list and return head of
that linked list.
#include<bits/stdc++.h>
using namespace std;
class Node{
public:
int data;
Node *next;
Node *prev;
Node(int data){
this->data = data;
this->next = NULL;
this->prev = NULL;
}
};
int main(){
Node *head = NULL;
insertAtBeg(head, 10);
insertAtBeg(head, 20);
insertAtBeg(head, 30);
insertAtBeg(head, 40);
insertAtBeg(head, 50);
insertAtEnd(head, 60);
insertAtEnd(head, 70);
insertAtEnd(head, 80);
insertAtEnd(head, 90);
insertAtEnd(head, 100);
display(head);
deleteAtEnd(head);
display(head);
deleteAtBeg(head);
display(head);
return 0;
}
5. Observations/Discussions/ Complexity Analysis:
• Time Complexity
o Insertion at beginning: O(1)
o Insertion at end: O(n)
o Deletion at beginning: O(1)
o Deletion at end: O(n)
• Space Complexity: O(N)
6. Result/Output/Writing Summary:
Output