Write a program to implement below operations with both sing
Write a program to implement below operations with both singly and doubly linked list. Use inheritance to define singly linked list and doubly linked list. Add Node() Delete Node() Update Node() Delete All() Size()
Solution
#include <iostream>
using namespace std;
class List;
class Node
{
friend class List;
protected:
int Data;
Node *Link;
};
class List:public Node
{
friend class Node;
private:
Node *Start;
public:
List()
{
Start=NULL;
}
Node Insert(int x);
Node Delete(int &x);
void Display();
};
Node List::Insert(int x)
{
Node *New=new Node;
New->Data=x;
New->Link=Start;
Start=New;
return *this;
}
Node List::Delete(int &x)//deletes first node
{
Node *Del=Start;
Start=Start->Link;
delete Del;
return *this;
}
void List::Display()
{
Node *P=Start;
while(P!=NULL)
{
cout<<P->Data<<\" \";
P=P->Link;
}
}
int main()
{
List L;
L.Insert(4);
L.Insert(64);
L.Insert(3);
L.Insert(90);
L.Insert(66);
L.Insert(13);
L.Display();
}
Double Linked List

