Professional Documents
Culture Documents
DSA Assignment2 Fall23
DSA Assignment2 Fall23
Assignment 2
CODE:
#include <iostream>
using namespace std;
template <class T>
class Node
{
T data;
Node<T> *next;
Node<T> *previous;
public:
Node(T d);
void setData(T d);
T getData();
void setNext(Node<T> *ptr);
void setPrevious(Node<T> *ptr);
Node<T>* getNext();
Node<T>* getPrevious();
};
int main()
{
// Declaring and Initializing different nodes.
Node<int> *n1, *n2, *n3, *n4, *n5, *n6, *n7, *n8;
n1 = new Node<int>(1);
n2 = new Node<int>(2);
n3 = new Node<int>(3);
n4 = new Node<int>(4);
n5 = new Node<int>(5);
n6 = new Node<int>(6);
n7 = new Node<int>(7);
n8 = new Node<int>(8);
Dlist<int> l;
l.insertNode(NULL, n1);
l.insertNode(n1, n2);
l.insertNode(n2, n3);
l.insertNode(n3, n4);
l.insertNode(n4, n5);
cout << " Printing the Doubly Linked list:" << endl;
l.printList();
cout << " Insertion at the First of the List: " << endl;
l.insertNode(n1, n7);
l.printList();
cout << " Insertion at the Last of the List: " << endl;
l.insertNode(n5, n6);
l.printList();
cout << " Insertion in the Middle of the List: " << endl;
l.insertNode(n4, n8);
l.printList();
cout << " Delteing node at the First of the List: " << endl;
l.deleteNode(n7);
l.printList();
cout << " Delteing node at the Last of the List: " << endl;
l.deleteNode(n6);
l.printList();
cout << " Delteing node in the Middle of the List: " << endl;
l.deleteNode(n8);
l.printList();
system("pause");
return 0;
}
Result:
CLOs
CLO2 The student has the ability to analyze and apply linear data structures in C4
programming language